From 05a3f7d8d61bc298809e5363d3a23aa16fe776d2 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Fri, 18 Nov 2022 19:37:58 +0000 Subject: [PATCH] Correctly handle Enum name on Python 3.11 (#14133) Fixes #12483 Fixes https://github.com/python/typeshed/issues/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. --- mypy/semanal.py | 8 +++++++- test-data/unit/pythoneval.test | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/mypy/semanal.py b/mypy/semanal.py index 9b2b4ba44cce..538e37c030a9 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -1448,7 +1448,13 @@ def visit_decorator(self, dec: Decorator) -> None: dec.var.is_classmethod = True self.check_decorated_function_is_method("classmethod", dec) elif refers_to_fullname( - d, ("builtins.property", "abc.abstractproperty", "functools.cached_property") + d, + ( + "builtins.property", + "abc.abstractproperty", + "functools.cached_property", + "enum.property", + ), ): removed.append(i) dec.func.is_property = True diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index f6336b48ee7b..3f669246bb4e 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -1712,3 +1712,26 @@ A = Type[int] | str B: TypeAlias = Type[int] | str [out] m.pyi:5: note: Revealed type is "typing._SpecialForm" + +[case testEnumNameWorkCorrectlyOn311] +# flags: --python-version 3.11 +import enum + +class E(enum.Enum): + X = 1 + Y = 2 + @enum.property + def foo(self) -> int: ... + +e: E +reveal_type(e.name) +reveal_type(e.value) +reveal_type(E.X.name) +reveal_type(e.foo) +reveal_type(E.Y.foo) +[out] +_testEnumNameWorkCorrectlyOn311.py:11: note: Revealed type is "builtins.str" +_testEnumNameWorkCorrectlyOn311.py:12: note: Revealed type is "Union[Literal[1]?, Literal[2]?]" +_testEnumNameWorkCorrectlyOn311.py:13: note: Revealed type is "Literal['X']?" +_testEnumNameWorkCorrectlyOn311.py:14: note: Revealed type is "builtins.int" +_testEnumNameWorkCorrectlyOn311.py:15: note: Revealed type is "builtins.int"