Skip to content

Commit 0fdfdc7

Browse files
JukkaLilevkivskyi
authored andcommitted
New semantic analyzer: fix order=True in dataclass with deferral (#6987)
Fixes #6954.
1 parent dfd50fc commit 0fdfdc7

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

mypy/plugins/dataclasses.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def transform(self) -> None:
149149
]
150150

151151
existing_method = info.get(method_name)
152-
if existing_method is not None:
152+
if existing_method is not None and not existing_method.plugin_generated:
153153
assert existing_method.node
154154
ctx.api.fail(
155155
'You may not have a custom %s method when order=True' % method_name,

test-data/unit/check-dataclasses.test

+18
Original file line numberDiff line numberDiff line change
@@ -624,3 +624,21 @@ class C:
624624
x: int = dataclasses.field(default=1)
625625
y: str = dataclasses.field(metadata={"doc": "foo"}) # E: Attributes without a default cannot follow attributes with one
626626
[builtins fixtures/dict.pyi]
627+
628+
[case testDataclassOrderingDeferred]
629+
# flags: --python-version 3.6 --new-semantic-analyzer
630+
from dataclasses import dataclass
631+
632+
defer: Yes
633+
634+
@dataclass(order=True)
635+
class Application:
636+
name: str
637+
rating: int
638+
639+
a = Application('', 0)
640+
b = Application('', 0)
641+
a < b
642+
643+
class Yes: ...
644+
[builtins fixtures/list.pyi]

0 commit comments

Comments
 (0)