diff --git a/mypy/semanal.py b/mypy/semanal.py index 3b9b96ca0ba17..7f346ac036ea2 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -3293,7 +3293,7 @@ def add_symbol(self, name: str, node: SymbolTableNode, self.locals[-1][name] = node elif self.type: existing = self.type.names.get(name) - if existing and existing.node != node.node: + if existing and isinstance(existing.node, TypeInfo) and existing.node != node.node: self.name_already_defined(name, context, existing) return self.type.names[name] = node diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index f53a5d22f8fdc..14ed21207a00d 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -5087,3 +5087,33 @@ c = D() from a import Other class B: ... [out] + +[case testAllowPropertyAndInit1] +class C: + def __init__(self, x: int) -> None: + self.x = x + @property + def x(self) -> int: pass + @x.setter + def x(self, x: int) -> None: pass +[builtins fixtures/property.pyi] +[out] + +[case testAllowPropertyAndInit2] +class C: + @property + def x(self) -> int: pass + @x.setter + def x(self, x: int) -> None: pass + def __init__(self, x: int) -> None: + self.x = x +[builtins fixtures/property.pyi] + +[case testAllowPropertyAndInit3] +class C: + def __init__(self, x: int) -> None: + self.x = x # type: ignore + @property # Should be no error here + def x(self) -> int: pass +[builtins fixtures/property.pyi] +[out]