Skip to content

Commit 65e950e

Browse files
committed
rm non-existing _DT from ordered dataclass
1 parent e5546fe commit 65e950e

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

mypy/plugins/dataclasses.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,7 @@ def transform(self) -> bool:
291291
self._api, self._cls, "__init__", args=args, return_type=NoneType()
292292
)
293293

294-
if (
295-
decorator_arguments["eq"]
296-
and info.get("__eq__") is None
297-
or decorator_arguments["order"]
298-
):
294+
if decorator_arguments["eq"] and info.get("__eq__") is None:
299295
# Type variable for self types in generated methods.
300296
obj_type = self._api.named_type("builtins.object")
301297
self_tvar_expr = TypeVarExpr(

test-data/unit/check-dataclasses.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,3 +2594,15 @@ class B2(B1): # E: A NamedTuple cannot be a dataclass
25942594
pass
25952595

25962596
[builtins fixtures/tuple.pyi]
2597+
2598+
[case testOrderedDataclassSelfTVARNotExist]
2599+
from dataclasses import dataclass
2600+
2601+
@dataclass(order=True)
2602+
class A:
2603+
b: int
2604+
2605+
a = A(1)
2606+
a._DT # E: "A" has no attribute "_DT"
2607+
2608+
[builtins fixtures/tuple.pyi]

test-data/unit/fixtures/tuple.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ _Tco = TypeVar('_Tco', covariant=True)
99
class object:
1010
def __init__(self) -> None: pass
1111
def __new__(cls) -> Self: ...
12+
def __eq__(self, other) -> bool: pass
1213

1314
class type:
1415
def __init__(self, *a: object) -> None: pass

0 commit comments

Comments
 (0)