Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2871,7 +2871,7 @@ def analyze_name_lvalue(self,
outer = self.is_global_or_nonlocal(name)
if kind == MDEF and isinstance(self.type, TypeInfo) and self.type.is_enum:
# Special case: we need to be sure that `Enum` keys are unique.
if existing:
if existing is not None and not isinstance(existing.node, PlaceholderNode):
self.fail('Attempted to reuse member name "{}" in Enum definition "{}"'.format(
name, self.type.name,
), lvalue)
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -1810,4 +1810,4 @@ reveal_type(A.str.value) # N: Revealed type is "Literal['foo']?"
reveal_type(A.int.value) # N: Revealed type is "Literal[1]?"
reveal_type(A.bool.value) # N: Revealed type is "Literal[False]?"
reveal_type(A.tuple.value) # N: Revealed type is "Tuple[Literal[1]?]"
[builtins fixtures/tuple.pyi]
[builtins fixtures/tuple.pyi]
12 changes: 12 additions & 0 deletions test-data/unit/pythoneval.test
Original file line number Diff line number Diff line change
Expand Up @@ -1573,3 +1573,15 @@ x: OrderedDict[str, str] = OrderedDict({})
reveal_type(x) # Revealed type is "collections.OrderedDict[builtins.str, builtins.int]"
[out]
_testTypingExtensionsOrderedDictAlias.py:3: note: Revealed type is "collections.OrderedDict[builtins.str, builtins.str]"

[case testEnumValueWithPlaceholderNodeType]
# https://github.com/python/mypy/issues/11971
from enum import Enum
from typing import Callable, Dict
class Foo(Enum):
Bar: Foo = Callable[[str], None]
Baz: Foo = Callable[[Dict[str, "Missing"]], None]
[out]
_testEnumValueWithPlaceholderNodeType.py:5: error: Incompatible types in assignment (expression has type "object", variable has type "Foo")
_testEnumValueWithPlaceholderNodeType.py:6: error: Incompatible types in assignment (expression has type "object", variable has type "Foo")
_testEnumValueWithPlaceholderNodeType.py:6: error: Name "Missing" is not defined