Skip to content

Commit

Permalink
Special case types.DynamicClassAttribute as property-like (#18150)
Browse files Browse the repository at this point in the history
This enables typeshed to define types.DynamicClassAttribute as a
different class from builtins.property without breakage.

Would enable python/typeshed#12762
see also #14133
  • Loading branch information
tungol authored Nov 21, 2024
1 parent eec8071 commit e840275
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,7 @@ def visit_decorator(self, dec: Decorator) -> None:
"abc.abstractproperty",
"functools.cached_property",
"enum.property",
"types.DynamicClassAttribute",
),
):
removed.append(i)
Expand Down
18 changes: 18 additions & 0 deletions test-data/unit/pythoneval.test
Original file line number Diff line number Diff line change
Expand Up @@ -2163,3 +2163,21 @@ class C3[T1, T2](tuple[T1, ...]):

def func3(p: C3[int, object]):
x: C3[int, int] = p


[case testDynamicClassAttribute]
# Some things that can break if DynamicClassAttribute isn't handled properly
from types import DynamicClassAttribute
from enum import Enum

class TestClass:
@DynamicClassAttribute
def name(self) -> str: ...

class TestClass2(TestClass, Enum): ...

class Status(Enum):
ABORTED = -1

def imperfect(status: Status) -> str:
return status.name.lower()

0 comments on commit e840275

Please sign in to comment.