diff --git a/mypy/checker.py b/mypy/checker.py index ee0e1b62a211..0d586fa987e7 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -50,7 +50,7 @@ from mypy.visitor import NodeVisitor from mypy.join import join_types from mypy.treetransform import TransformVisitor -from mypy.meet import meet_simple, nearest_builtin_ancestor, is_overlapping_types +from mypy.meet import meet_simple, is_overlapping_types from mypy.binder import ConditionalTypeBinder from mypy.options import Options @@ -959,7 +959,6 @@ def visit_class_def(self, defn: ClassDef) -> Type: def check_multiple_inheritance(self, typ: TypeInfo) -> None: """Check for multiple inheritance related errors.""" - if len(typ.bases) <= 1: # No multiple inheritance. return @@ -973,13 +972,6 @@ def check_multiple_inheritance(self, typ: TypeInfo) -> None: # checks suffice (these are implemented elsewhere). if name in base2.names and base2 not in base.mro: self.check_compatibility(name, base, base2, typ) - # Verify that base class layouts are compatible. - builtin_bases = [nearest_builtin_ancestor(base.type) - for base in typ.bases] - for base1 in builtin_bases: - for base2 in builtin_bases: - if not (base1 in base2.mro or base2 in base1.mro): - self.fail(messages.INSTANCE_LAYOUT_CONFLICT, typ) def check_compatibility(self, name: str, base1: TypeInfo, base2: TypeInfo, ctx: Context) -> None: diff --git a/mypy/meet.py b/mypy/meet.py index 63e3aaee8bce..18796ae2491c 100644 --- a/mypy/meet.py +++ b/mypy/meet.py @@ -1,4 +1,4 @@ -from typing import cast, List +from typing import List from mypy.join import is_similar_callables, combine_similar_callables from mypy.types import ( @@ -7,7 +7,6 @@ DeletedType, UninhabitedType, TypeType ) from mypy.subtypes import is_subtype -from mypy.nodes import TypeInfo from mypy import experiments @@ -114,14 +113,6 @@ class C(A, B): ... return True -def nearest_builtin_ancestor(type: TypeInfo) -> TypeInfo: - for base in type.mro: - if base.defn.is_builtinclass: - return base - else: - return None - - class TypeMeetVisitor(TypeVisitor[Type]): def __init__(self, s: Type) -> None: self.s = s diff --git a/mypy/messages.py b/mypy/messages.py index e39a424fbf40..432f1ddaed7a 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -76,7 +76,6 @@ 'Overloaded method has both abstract and non-abstract variants' READ_ONLY_PROPERTY_OVERRIDES_READ_WRITE = \ 'Read-only property cannot override read-write property' -INSTANCE_LAYOUT_CONFLICT = 'Instance layout conflict in multiple inheritance' FORMAT_REQUIRES_MAPPING = 'Format requires a mapping' GENERIC_TYPE_NOT_VALID_AS_EXPRESSION = \ "Generic type is prohibited as a runtime expression (use a type alias or '# type:' comment)" diff --git a/mypy/nodes.py b/mypy/nodes.py index 7cc2d44d401e..36cb0a2a2210 100644 --- a/mypy/nodes.py +++ b/mypy/nodes.py @@ -694,8 +694,6 @@ class ClassDef(Statement): info = None # type: TypeInfo # Related TypeInfo metaclass = '' decorators = None # type: List[Expression] - # Built-in/extension class? (single implementation inheritance only) - is_builtinclass = False has_incompatible_baseclass = False def __init__(self, @@ -724,7 +722,6 @@ def serialize(self) -> JsonDict: 'fullname': self.fullname, 'type_vars': [v.serialize() for v in self.type_vars], 'metaclass': self.metaclass, - 'is_builtinclass': self.is_builtinclass, } @classmethod @@ -736,7 +733,6 @@ def deserialize(self, data: JsonDict) -> 'ClassDef': metaclass=data['metaclass'], ) res.fullname = data['fullname'] - res.is_builtinclass = data['is_builtinclass'] return res diff --git a/mypy/semanal.py b/mypy/semanal.py index dccd260b3669..71d4dda12fe9 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -559,8 +559,6 @@ def visit_class_def(self, defn: ClassDef) -> None: self.enter_class(defn) - self.setup_is_builtinclass(defn) - # Analyze class body. defn.defs.accept(self) @@ -606,15 +604,6 @@ def unbind_class_type_vars(self) -> None: def analyze_class_decorator(self, defn: ClassDef, decorator: Expression) -> None: decorator.accept(self) - def setup_is_builtinclass(self, defn: ClassDef) -> None: - for decorator in defn.decorators: - if refers_to_fullname(decorator, 'typing.builtinclass'): - defn.is_builtinclass = True - if defn.fullname == 'builtins.object': - # Only 'object' is marked as a built-in class, as otherwise things elsewhere - # would break. We need a better way of dealing with built-in classes. - defn.is_builtinclass = True - def calculate_abstract_status(self, typ: TypeInfo) -> None: """Calculate abstract status of a class. diff --git a/mypy/strconv.py b/mypy/strconv.py index bb167f1ef8b6..ba01ea88e628 100644 --- a/mypy/strconv.py +++ b/mypy/strconv.py @@ -141,8 +141,6 @@ def visit_class_def(self, o: 'mypy.nodes.ClassDef') -> str: a.insert(1, 'Metaclass({})'.format(o.metaclass)) if o.decorators: a.insert(1, ('Decorators', o.decorators)) - if o.is_builtinclass: - a.insert(1, 'Builtinclass') if o.info and o.info._promote: a.insert(1, 'Promote({})'.format(o.info._promote)) if o.info and o.info.tuple_type: diff --git a/mypy/treetransform.py b/mypy/treetransform.py index c030f0e1e5dc..31644a5700e8 100644 --- a/mypy/treetransform.py +++ b/mypy/treetransform.py @@ -190,7 +190,6 @@ def visit_class_def(self, node: ClassDef) -> ClassDef: new.info = node.info new.decorators = [self.expr(decorator) for decorator in node.decorators] - new.is_builtinclass = node.is_builtinclass return new def visit_global_decl(self, node: GlobalDecl) -> GlobalDecl: diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index e63dbce9d637..4812eaf16ca0 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -894,26 +894,6 @@ a.f = a.f # E: Property "f" defined in "A" is read-only a.f.x # E: "int" has no attribute "x" [builtins fixtures/property.pyi] - --- Multiple inheritance, non-object built-in class as base --- ------------------------------------------------------- - - -[case testInvalidMultipleInheritanceFromBuiltins-skip] -import typing -class A(int, str): pass # E: Instance layout conflict in multiple inheritance -[out] -main: note: In class "A": - -[case testInvalidMultipleInheritanceFromBuiltins-skip] -import typing -class S(str): pass -class A(S, str): pass -class B(S, int): pass # E: Instance layout conflict in multiple inheritance -[out] -main: note: In class "B": - - -- _promote decorators -- ------------------- diff --git a/test-data/unit/check-overloading.test b/test-data/unit/check-overloading.test index a7e11597c70d..8fdfda49a71e 100644 --- a/test-data/unit/check-overloading.test +++ b/test-data/unit/check-overloading.test @@ -411,10 +411,10 @@ A() + B() A() + '' # E: No overload variant of "__add__" of "A" matches argument types [builtins.str] [case testOverrideOverloadedMethodWithMoreGeneralArgumentTypes] -from typing import overload, builtinclass -@builtinclass +from typing import overload + class IntSub(int): pass -@builtinclass + class StrSub(str): pass class A: @overload @@ -429,10 +429,10 @@ class B(A): [out] [case testOverrideOverloadedMethodWithMoreSpecificArgumentTypes] -from typing import overload, builtinclass -@builtinclass +from typing import overload + class IntSub(int): pass -@builtinclass + class StrSub(str): pass class A: @overload @@ -461,12 +461,10 @@ main: note: In class "C": main:17: error: Signature of "f" incompatible with supertype "A" [case testOverloadingAndDucktypeCompatibility] -from typing import overload, _promote, builtinclass +from typing import overload, _promote -@builtinclass class A: pass -@builtinclass @_promote(A) class B: pass diff --git a/test-data/unit/semanal-classes.test b/test-data/unit/semanal-classes.test index 5d04ef6818c5..431261fa3a18 100644 --- a/test-data/unit/semanal-classes.test +++ b/test-data/unit/semanal-classes.test @@ -518,20 +518,6 @@ MypyFile:1( NameExpr(object [builtins.object])) PassStmt:3())) -[case testBuiltinclassDecorator] -from typing import builtinclass -@builtinclass -class A: pass -[out] -MypyFile:1( - ImportFrom:1(typing, [builtinclass]) - ClassDef:2( - A - Builtinclass - Decorators( - NameExpr(builtinclass [typing.builtinclass])) - PassStmt:3())) - [case testClassAttributeAsMethodDefaultArgumentValue] import typing class A: diff --git a/test-data/unit/typexport-basic.test b/test-data/unit/typexport-basic.test index 2c668f8d557d..e7915cc60f8a 100644 --- a/test-data/unit/typexport-basic.test +++ b/test-data/unit/typexport-basic.test @@ -136,8 +136,6 @@ import typing 8 > 3 4 < 6 > 2 [file builtins.py] -from typing import builtinclass -@builtinclass class object: def __init__(self) -> None: pass class int: