Skip to content

Remove @builtinclass #2294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
11 changes: 1 addition & 10 deletions mypy/meet.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -7,7 +7,6 @@
DeletedType, UninhabitedType, TypeType
)
from mypy.subtypes import is_subtype
from mypy.nodes import TypeInfo

from mypy import experiments

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
4 changes: 0 additions & 4 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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


Expand Down
11 changes: 0 additions & 11 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.

Expand Down
2 changes: 0 additions & 2 deletions mypy/strconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion mypy/treetransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 0 additions & 20 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
-- -------------------

Expand Down
16 changes: 7 additions & 9 deletions test-data/unit/check-overloading.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
14 changes: 0 additions & 14 deletions test-data/unit/semanal-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions test-data/unit/typexport-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down