Skip to content

Commit

Permalink
Changed synthesized comparison methods (__lt__, etc.) for dataclass…
Browse files Browse the repository at this point in the history
…es when `order=True` to use `Self` rather than an instance of the class. This is not only more consistent with other synthesized methods, but it also preserves covariance of type variables if the dataclass is frozen. (#8734)
  • Loading branch information
erictraut authored Aug 10, 2024
1 parent 465b04c commit 1a17c0a
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions packages/pyright-internal/src/analyzer/dataClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,8 @@ export function synthesizeDataClassMethods(
}

if (ClassType.isDataClassGenerateOrder(classType)) {
const objType = ClassType.cloneAsInstance(classType);
['__lt__', '__le__', '__gt__', '__ge__'].forEach((operator) => {
synthesizeComparisonMethod(operator, objType);
synthesizeComparisonMethod(operator, selfType);
});
}

Expand Down

0 comments on commit 1a17c0a

Please sign in to comment.