Skip to content

Commit 05a3f7d

Browse files
authored
Correctly handle Enum name on Python 3.11 (#14133)
Fixes #12483 Fixes python/typeshed#7564 Ref #12841 The fix is straightforward. I can't use a unit test for this because there are some builtins fixtures that don't have tuple, so I can't do version check.
1 parent 1cc4a7d commit 05a3f7d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

mypy/semanal.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,13 @@ def visit_decorator(self, dec: Decorator) -> None:
14481448
dec.var.is_classmethod = True
14491449
self.check_decorated_function_is_method("classmethod", dec)
14501450
elif refers_to_fullname(
1451-
d, ("builtins.property", "abc.abstractproperty", "functools.cached_property")
1451+
d,
1452+
(
1453+
"builtins.property",
1454+
"abc.abstractproperty",
1455+
"functools.cached_property",
1456+
"enum.property",
1457+
),
14521458
):
14531459
removed.append(i)
14541460
dec.func.is_property = True

test-data/unit/pythoneval.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,3 +1712,26 @@ A = Type[int] | str
17121712
B: TypeAlias = Type[int] | str
17131713
[out]
17141714
m.pyi:5: note: Revealed type is "typing._SpecialForm"
1715+
1716+
[case testEnumNameWorkCorrectlyOn311]
1717+
# flags: --python-version 3.11
1718+
import enum
1719+
1720+
class E(enum.Enum):
1721+
X = 1
1722+
Y = 2
1723+
@enum.property
1724+
def foo(self) -> int: ...
1725+
1726+
e: E
1727+
reveal_type(e.name)
1728+
reveal_type(e.value)
1729+
reveal_type(E.X.name)
1730+
reveal_type(e.foo)
1731+
reveal_type(E.Y.foo)
1732+
[out]
1733+
_testEnumNameWorkCorrectlyOn311.py:11: note: Revealed type is "builtins.str"
1734+
_testEnumNameWorkCorrectlyOn311.py:12: note: Revealed type is "Union[Literal[1]?, Literal[2]?]"
1735+
_testEnumNameWorkCorrectlyOn311.py:13: note: Revealed type is "Literal['X']?"
1736+
_testEnumNameWorkCorrectlyOn311.py:14: note: Revealed type is "builtins.int"
1737+
_testEnumNameWorkCorrectlyOn311.py:15: note: Revealed type is "builtins.int"

0 commit comments

Comments
 (0)