8000 Fix `Enum` final props and writable special members, refs #11820 (#11… · python/mypy@f6ebf10 · GitHub
[go: up one dir, main page]

Skip to content

Commit f6ebf10

Browse files
authored
Fix Enum final props and writable special members, refs #11820 (#11945)
1 parent 6ea7cfa commit f6ebf10

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,7 @@ def check_compatibility_final_super(self, node: Var,
25172517
self.msg.cant_override_final(node.name, base.name, node)
25182518
return False
25192519
if node.is_final:
2520-
if base.fullname in ENUM_BASES and node.name in ENUM_SPECIAL_PROPS:
2520+
if base.fullname in ENUM_BASES or node.name in ENUM_SPECIAL_PROPS:
25212521
return True
25222522
self.check_if_final_var_override_writable(node.name, base_node, node)
25232523
return True

test-data/unit/check-enum.test

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,9 +1712,17 @@ class B(A): pass # E: Cannot inherit from final class "A"
17121712

17131713
[case testEnumFinalSpecialProps]
17141714
# https://github.com/python/mypy/issues/11699
1715+
# https://github.com/python/mypy/issues/11820
17151716
from enum import Enum, IntEnum
17161717

1717-
class E(Enum):
1718+
class BaseWithSpecials:
1719+
__slots__ = ()
1720+
__doc__ = 'doc'
1721+
__module__ = 'module'
1722+
__annotations__ = {'a': int}
1723+
__dict__ = {'a': 1}
1724+
1725+
class E(BaseWithSpecials, Enum):
17181726
name = 'a'
17191727
value = 'b'
17201728
_name_ = 'a1'

0 commit comments

Comments
 (0)
0