diff --git a/test-data/unit/check-enum.test b/test-data/unit/check-enum.test index 00d9123ff3b3..41bd708db0e8 100644 --- a/test-data/unit/check-enum.test +++ b/test-data/unit/check-enum.test @@ -2208,3 +2208,23 @@ class Pet(Enum): DOG: str = ... # E: Enum members must be left unannotated \ # N: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members \ # E: Incompatible types in assignment (expression has type "ellipsis", variable has type "str") + +[case testEnumValueWithPlaceholderNodeType] +# https://github.com/python/mypy/issues/11971 +from enum import Enum +from typing import Any, Callable, Dict +class Foo(Enum): + Bar: Foo = Callable[[str], None] # E: Enum members must be left unannotated \ + # N: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members \ + # E: Value of type "int" is not indexable + Baz: Any = Callable[[Dict[str, "Missing"]], None] # E: Enum members must be left unannotated \ + # N: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members \ + # E: Value of type "int" is not indexable \ + # E: Type application targets a non-generic function or class \ + # E: Name "Missing" is not defined + +reveal_type(Foo.Bar) # N: Revealed type is "Literal[__main__.Foo.Bar]?" +reveal_type(Foo.Bar.value) # N: Revealed type is "__main__.Foo" +reveal_type(Foo.Baz) # N: Revealed type is "Literal[__main__.Foo.Baz]?" +reveal_type(Foo.Baz.value) # N: Revealed type is "Any" +[builtins fixtures/tuple.pyi] diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index 398cdf500c50..e73dbf79a0ec 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -1596,28 +1596,6 @@ if isinstance(obj, Awaitable): _testSpecialTypingProtocols.py:6: note: Revealed type is "Tuple[builtins.int]" _testSpecialTypingProtocols.py:8: error: Statement is unreachable -[case testEnumValueWithPlaceholderNodeType] -# https://github.com/python/mypy/issues/11971 -from enum import Enum -from typing import Any, Callable, Dict -class Foo(Enum): - Bar: Foo = Callable[[str], None] - Baz: Any = Callable[[Dict[str, "Missing"]], None] - -reveal_type(Foo.Bar) -reveal_type(Foo.Bar.value) # this should probably not be "Foo" https://typing.readthedocs.io/en/latest/spec/enums.html#member-values -reveal_type(Foo.Baz) -reveal_type(Foo.Baz.value) -[out] -_testEnumValueWithPlaceholderNodeType.py:5: error: Enum members must be left unannotated -_testEnumValueWithPlaceholderNodeType.py:5: error: Incompatible types in assignment (expression has type "", variable has type "Foo") -_testEnumValueWithPlaceholderNodeType.py:6: error: Enum members must be left unannotated -_testEnumValueWithPlaceholderNodeType.py:6: error: Name "Missing" is not defined -_testEnumValueWithPlaceholderNodeType.py:8: note: Revealed type is "Literal[_testEnumValueWithPlaceholderNodeType.Foo.Bar]?" -_testEnumValueWithPlaceholderNodeType.py:9: note: Revealed type is "_testEnumValueWithPlaceholderNodeType.Foo" -_testEnumValueWithPlaceholderNodeType.py:10: note: Revealed type is "Literal[_testEnumValueWithPlaceholderNodeType.Foo.Baz]?" -_testEnumValueWithPlaceholderNodeType.py:11: note: Revealed type is "Any" - [case testTypeshedRecursiveTypesExample] from typing import List, Union