diff --git a/mypy/plugins/dataclasses.py b/mypy/plugins/dataclasses.py index f2ae3fd3d01e4..a51b393fcbc43 100644 --- a/mypy/plugins/dataclasses.py +++ b/mypy/plugins/dataclasses.py @@ -23,6 +23,7 @@ ClassDef, Context, DataclassTransformSpec, + Decorator, Expression, FuncDef, FuncItem, @@ -575,6 +576,10 @@ def collect_attributes(self) -> list[DataclassAttribute] | None: # but the only alternative would be to modify the SymbolTable, # and it's a little hairy to do that in a plugin. continue + if isinstance(node, Decorator): + # This might be a property / field name clash. + # We will issue an error later. + continue assert isinstance(node, Var) diff --git a/test-data/unit/check-dataclasses.test b/test-data/unit/check-dataclasses.test index 35df84658259f..d37ae569cc5ea 100644 --- a/test-data/unit/check-dataclasses.test +++ b/test-data/unit/check-dataclasses.test @@ -2519,3 +2519,15 @@ a: MyDataclass b = [a, a] # trigger joining the types [builtins fixtures/dataclasses.pyi] + +[case testPropertyAndFieldRedefinitionNoCrash] +from dataclasses import dataclass + +@dataclass +class Foo: + @property + def c(self) -> int: + return 0 + + c: int # E: Name "c" already defined on line 5 +[builtins fixtures/dataclasses.pyi]