From 3b3bbcb0ad55ae85b4c3bacf6962ab8c43acc2df Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sun, 9 Jan 2022 16:00:07 +0300 Subject: [PATCH] Fix `Enum` final props and writable special members, refs #11820 --- mypy/checker.py | 2 +- test-data/unit/check-enum.test | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mypy/checker.py b/mypy/checker.py index 51aa7a3942fff..ce1859c02a201 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -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 diff --git a/test-data/unit/check-enum.test b/test-data/unit/check-enum.test index d80cd4822b8ce..8024fbcf7e3fb 100644 --- a/test-data/unit/check-enum.test +++ b/test-data/unit/check-enum.test @@ -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'