Skip to content

Commit

Permalink
Fix Enum final props and writable special members, refs #11820 (#11945
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sobolevn authored Jan 10, 2022
1 parent 6ea7cfa commit f6ebf10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2517,7 +2517,7 @@ def check_compatibility_final_super(self, node: Var,
self.msg.cant_override_final(node.name, base.name, node)
return False
if node.is_final:
if base.fullname in ENUM_BASES and node.name in ENUM_SPECIAL_PROPS:
if base.fullname in ENUM_BASES or node.name in ENUM_SPECIAL_PROPS:
return True
self.check_if_final_var_override_writable(node.name, base_node, node)
return True
Expand Down
10 changes: 9 additions & 1 deletion test-data/unit/check-enum.test
Original file line number Diff line number Diff line change
Expand Up @@ -1712,9 +1712,17 @@ class B(A): pass # E: Cannot inherit from final class "A"

[case testEnumFinalSpecialProps]
# https://github.com/python/mypy/issues/11699
# https://github.com/python/mypy/issues/11820
from enum import Enum, IntEnum

class E(Enum):
class BaseWithSpecials:
__slots__ = ()
__doc__ = 'doc'
__module__ = 'module'
__annotations__ = {'a': int}
__dict__ = {'a': 1}

class E(BaseWithSpecials, Enum):
name = 'a'
value = 'b'
_name_ = 'a1'
Expand Down

0 comments on commit f6ebf10

Please sign in to comment.