Skip to content

Commit e840275

Browse files
authored
Special case types.DynamicClassAttribute as property-like (#18150)
This enables typeshed to define types.DynamicClassAttribute as a different class from builtins.property without breakage. Would enable python/typeshed#12762 see also #14133
1 parent eec8071 commit e840275

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

mypy/semanal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,7 @@ def visit_decorator(self, dec: Decorator) -> None:
16841684
"abc.abstractproperty",
16851685
"functools.cached_property",
16861686
"enum.property",
1687+
"types.DynamicClassAttribute",
16871688
),
16881689
):
16891690
removed.append(i)

test-data/unit/pythoneval.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,3 +2163,21 @@ class C3[T1, T2](tuple[T1, ...]):
21632163

21642164
def func3(p: C3[int, object]):
21652165
x: C3[int, int] = p
2166+
2167+
2168+
[case testDynamicClassAttribute]
2169+
# Some things that can break if DynamicClassAttribute isn't handled properly
2170+
from types import DynamicClassAttribute
2171+
from enum import Enum
2172+
2173+
class TestClass:
2174+
@DynamicClassAttribute
2175+
def name(self) -> str: ...
2176+
2177+
class TestClass2(TestClass, Enum): ...
2178+
2179+
class Status(Enum):
2180+
ABORTED = -1
2181+
2182+
def imperfect(status: Status) -> str:
2183+
return status.name.lower()

0 commit comments

Comments
 (0)