Skip to content

Commit

Permalink
Correctly handle Enum name on Python 3.11 (#14133)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ilevkivskyi committed Nov 18, 2022
1 parent 1cc4a7d commit 05a3f7d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions test-data/unit/pythoneval.test
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 05a3f7d

Please sign in to comment.