|
37 | 37 | import mypy.checkexpr
|
38 | 38 | from mypy.checkmember import (
|
39 | 39 | map_type_from_supertype, bind_self, erase_to_bound, type_object_type,
|
40 |
| - analyze_descriptor_access |
| 40 | + analyze_descriptor_access, is_final_node |
41 | 41 | )
|
42 | 42 | from mypy import messages
|
43 | 43 | from mypy.subtypes import (
|
@@ -1263,8 +1263,7 @@ def check_method_or_accessor_override_for_base(self, defn: Union[FuncBase, Decor
|
1263 | 1263 | base_attr = base.names.get(name)
|
1264 | 1264 | if base_attr:
|
1265 | 1265 | # First, check if we override a final (always an error, even with Any types).
|
1266 |
| - if (isinstance(base_attr.node, (Var, FuncBase, Decorator)) |
1267 |
| - and base_attr.node.is_final): |
| 1266 | + if is_final_node(base_attr.node): |
1268 | 1267 | self.msg.cant_override_final(name, base.name(), defn)
|
1269 | 1268 | # Second, final can't override anything writeable independently of types.
|
1270 | 1269 | if defn.is_final:
|
@@ -1330,10 +1329,8 @@ def check_method_override_for_base_with_name(
|
1330 | 1329 | if isinstance(original_type, AnyType) or isinstance(typ, AnyType):
|
1331 | 1330 | pass
|
1332 | 1331 | elif isinstance(original_type, FunctionLike) and isinstance(typ, FunctionLike):
|
1333 |
| - # mypyc hack to workaround mypy misunderstanding multiple inheritance (#3603) |
1334 |
| - base_attr_node = base_attr.node # type: Any |
1335 |
| - if (isinstance(base_attr_node, (FuncBase, Decorator)) |
1336 |
| - and not is_static(base_attr_node)): |
| 1332 | + if (isinstance(base_attr.node, (FuncDef, OverloadedFuncDef, Decorator)) |
| 1333 | + and not is_static(base_attr.node)): |
1337 | 1334 | bound = bind_self(original_type, self.scope.active_self_type())
|
1338 | 1335 | else:
|
1339 | 1336 | bound = original_type
|
@@ -1587,9 +1584,9 @@ def check_compatibility(self, name: str, base1: TypeInfo,
|
1587 | 1584 | ok = True
|
1588 | 1585 | # Final attributes can never be overridden, but can override
|
1589 | 1586 | # non-final read-only attributes.
|
1590 |
| - if isinstance(second.node, (Var, FuncBase, Decorator)) and second.node.is_final: |
| 1587 | + if is_final_node(second.node): |
1591 | 1588 | self.msg.cant_override_final(name, base2.name(), ctx)
|
1592 |
| - if isinstance(first.node, (Var, FuncBase, Decorator)) and first.node.is_final: |
| 1589 | + if is_final_node(first.node): |
1593 | 1590 | self.check_no_writable(name, second.node, ctx)
|
1594 | 1591 | # __slots__ is special and the type can vary across class hierarchy.
|
1595 | 1592 | if name == '__slots__':
|
|
0 commit comments