Skip to content
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

Implementing background infrastructure for recursive types: Part 1 #7330

Merged
merged 19 commits into from
Aug 16, 2019
Merged
Prev Previous commit
Next Next commit
More comments and formatting
  • Loading branch information
Ivan Levkivskyi committed Aug 13, 2019
commit 1a9131d30d4a381c5202b8b5939fccf9e74315d8
12 changes: 12 additions & 0 deletions misc/proper_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@


class ProperTypePlugin(Plugin):
"""
A plugin to ensure that every type is expanded before doing any special-casing.

This solves the problem that we have hundreds of call sites like:

if isinstance(typ, UnionType):
... # special-case union

But after introducing a new type TypeAliasType (and removing immediate expansion)
all these became dangerous because typ may be e.g. an alias to union.
"""
def get_function_hook(self, fullname: str
) -> Optional[Callable[[FunctionContext], Type]]:
if fullname == 'builtins.isinstance':
Expand Down Expand Up @@ -45,6 +56,7 @@ def isinstance_proper_hook(ctx: FunctionContext) -> Type:


def is_improper_type(typ: Type) -> bool:
"""Is this a type that is not a subtype of ProperType?"""
typ = get_proper_type(typ)
if isinstance(typ, Instance):
info = typ.type
Expand Down
2 changes: 1 addition & 1 deletion mypy/server/astdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class level -- these are handled at attribute level (say, 'mod.Cls.method'
from mypy.types import (
Type, TypeVisitor, UnboundType, AnyType, NoneType, UninhabitedType,
ErasedType, DeletedType, Instance, TypeVarType, CallableType, TupleType, TypedDictType,
UnionType, Overloaded, PartialType, TypeType, LiteralType
UnionType, Overloaded, PartialType, TypeType, LiteralType,
)
from mypy.util import get_prefix

Expand Down
2 changes: 1 addition & 1 deletion mypy/server/astmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
Type, SyntheticTypeVisitor, Instance, AnyType, NoneType, CallableType, DeletedType,
TupleType, TypeType, TypeVarType, TypedDictType, UnboundType, UninhabitedType, UnionType,
Overloaded, TypeVarDef, TypeList, CallableArgument, EllipsisType, StarType, LiteralType,
RawExpressionType, PartialType
RawExpressionType, PartialType,
)
from mypy.util import get_prefix, replace_object_state
from mypy.typestate import TypeState
Expand Down