From 7ffcd92a2a1037b3337cd7681a7334709e859b9b Mon Sep 17 00:00:00 2001
From: Jukka Lehtosalo <jukka.lehtosalo@iki.fi>
Date: Thu, 13 Jun 2019 15:00:15 +0100
Subject: [PATCH] New semantic analyzer: fix order=True in dataclass with
 deferral

Fixes #6954.
---
 mypy/plugins/dataclasses.py           |  2 +-
 test-data/unit/check-dataclasses.test | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

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]