Skip to content

Commit

Permalink
Fixes regression with __module__ and similar non-final Enum names…
Browse files Browse the repository at this point in the history
…, refs #11820 (#11823)
  • Loading branch information
sobolevn authored and JukkaL committed Jan 5, 2022
1 parent 3773d2d commit da6be94
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mypy/semanal_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
))
ENUM_SPECIAL_PROPS: Final = frozenset((
'name', 'value', '_name_', '_value_', '_order_', '__order__',
# Also attributes from `object`:
'__module__', '__annotations__', '__doc__', '__slots__', '__dict__',
))


Expand Down
12 changes: 11 additions & 1 deletion test-data/unit/check-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,11 @@ class E(Enum):
_value_ = 'b2'
_order_ = 'X Y'
__order__ = 'X Y'
__slots__ = ()
__doc__ = 'doc'
__module__ = 'module'
__annotations__ = {'a': int}
__dict__ = {'a': 1}

class EI(IntEnum):
name = 'a'
Expand All @@ -1697,10 +1702,15 @@ class EI(IntEnum):
_value_ = 2
_order_ = 'X Y'
__order__ = 'X Y'
__slots__ = ()
__doc__ = 'doc'
__module__ = 'module'
__annotations__ = {'a': int}
__dict__ = {'a': 1}

E._order_ = 'a' # E: Cannot assign to final attribute "_order_"
EI.value = 2 # E: Cannot assign to final attribute "value"
[builtins fixtures/bool.pyi]
[builtins fixtures/dict.pyi]

[case testEnumNotFinalWithMethodsAndUninitializedValues]
# https://github.com/python/mypy/issues/11578
Expand Down

0 comments on commit da6be94

Please sign in to comment.