diff --git a/mypy/plugins/dataclasses.py b/mypy/plugins/dataclasses.py index 31e725a8cfc4..4b4826f27762 100644 --- a/mypy/plugins/dataclasses.py +++ b/mypy/plugins/dataclasses.py @@ -149,7 +149,7 @@ def transform(self) -> None: ] existing_method = info.get(method_name) - if existing_method is not None: + if existing_method is not None and not existing_method.plugin_generated: assert existing_method.node ctx.api.fail( 'You may not have a custom %s method when order=True' % method_name, diff --git a/test-data/unit/check-dataclasses.test b/test-data/unit/check-dataclasses.test index 47ec45e5e8bb..65cc4768143f 100644 --- a/test-data/unit/check-dataclasses.test +++ b/test-data/unit/check-dataclasses.test @@ -624,3 +624,21 @@ class C: x: int = dataclasses.field(default=1) y: str = dataclasses.field(metadata={"doc": "foo"}) # E: Attributes without a default cannot follow attributes with one [builtins fixtures/dict.pyi] + +[case testDataclassOrderingDeferred] +# flags: --python-version 3.6 --new-semantic-analyzer +from dataclasses import dataclass + +defer: Yes + +@dataclass(order=True) +class Application: + name: str + rating: int + +a = Application('', 0) +b = Application('', 0) +a < b + +class Yes: ... +[builtins fixtures/list.pyi]