-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Make TypeVisitor and SyntheticTypeVisitor (almost) fully abstract #7312
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
Changes from all commits
2a550d8
2edff9a
d27ab28
8d576f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,10 +56,10 @@ | |
) | ||
from mypy.traverser import TraverserVisitor | ||
from mypy.types import ( | ||
Type, SyntheticTypeVisitor, Instance, AnyType, NoneType, CallableType, DeletedType, | ||
Type, SyntheticTypeVisitor, Instance, AnyType, NoneType, CallableType, ErasedType, DeletedType, | ||
TupleType, TypeType, TypeVarType, TypedDictType, UnboundType, UninhabitedType, UnionType, | ||
Overloaded, TypeVarDef, TypeList, CallableArgument, EllipsisType, StarType, LiteralType, | ||
RawExpressionType, PartialType, | ||
RawExpressionType, PartialType, PlaceholderType, | ||
) | ||
from mypy.util import get_prefix, replace_object_state | ||
from mypy.typestate import TypeState | ||
|
@@ -373,6 +373,10 @@ def visit_overloaded(self, t: Overloaded) -> None: | |
if t.fallback is not None: | ||
t.fallback.accept(self) | ||
|
||
def visit_erased_type(self, t: ErasedType) -> None: | ||
# This type should exist only temporarily during type inference | ||
raise RuntimeError | ||
|
||
def visit_deleted_type(self, typ: DeletedType) -> None: | ||
pass | ||
|
||
|
@@ -429,6 +433,10 @@ def visit_union_type(self, typ: UnionType) -> None: | |
for item in typ.items: | ||
item.accept(self) | ||
|
||
def visit_placeholder_type(self, t: PlaceholderType) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this also should raise, since this should be called after semantic analysis is done. But maybe I am wrong because there are many visit methods for synthetic types. Or maybe it was mistakenly made There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it was intentional that this visitor is a SyntheticTypeVisitor -- we apparently try running this visitor on |
||
for item in t.args: | ||
item.accept(self) | ||
|
||
# Helpers | ||
|
||
def fixup(self, node: SN) -> SN: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ class 'mod.Cls'. This can also refer to an attribute inherited from a | |
from mypy.types import ( | ||
Type, Instance, AnyType, NoneType, TypeVisitor, CallableType, DeletedType, PartialType, | ||
TupleType, TypeType, TypeVarType, TypedDictType, UnboundType, UninhabitedType, UnionType, | ||
FunctionLike, Overloaded, TypeOfAny, LiteralType, get_proper_type, ProperType | ||
FunctionLike, Overloaded, TypeOfAny, LiteralType, ErasedType, get_proper_type, ProperType | ||
) | ||
from mypy.server.trigger import make_trigger, make_wildcard_trigger | ||
from mypy.util import correct_relative_import | ||
|
@@ -901,6 +901,10 @@ def visit_overloaded(self, typ: Overloaded) -> List[str]: | |
triggers.extend(self.get_type_triggers(item)) | ||
return triggers | ||
|
||
def visit_erased_type(self, t: ErasedType) -> List[str]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this one too. |
||
# This type should exist only temporarily during type inference | ||
assert False, "Should not see an erased type here" | ||
|
||
def visit_deleted_type(self, typ: DeletedType) -> List[str]: | ||
return [] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,10 @@ | |
from mypy.options import Options | ||
from mypy.types import ( | ||
Type, UnboundType, TypeVarType, TupleType, TypedDictType, UnionType, Instance, AnyType, | ||
CallableType, NoneType, DeletedType, TypeList, TypeVarDef, SyntheticTypeVisitor, | ||
CallableType, NoneType, ErasedType, DeletedType, TypeList, TypeVarDef, SyntheticTypeVisitor, | ||
StarType, PartialType, EllipsisType, UninhabitedType, TypeType, replace_alias_tvars, | ||
CallableArgument, get_type_vars, TypeQuery, union_items, TypeOfAny, | ||
LiteralType, RawExpressionType, PlaceholderType, get_proper_type, ProperType | ||
LiteralType, RawExpressionType, PlaceholderType, Overloaded, get_proper_type, ProperType | ||
) | ||
|
||
from mypy.nodes import ( | ||
|
@@ -456,6 +456,10 @@ def visit_none_type(self, t: NoneType) -> Type: | |
def visit_uninhabited_type(self, t: UninhabitedType) -> Type: | ||
return t | ||
|
||
def visit_erased_type(self, t: ErasedType) -> Type: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this too should raise, see |
||
# This type should exist only temporarily during type inference | ||
assert False, "Internal error: Unexpected erased type" | ||
|
||
def visit_deleted_type(self, t: DeletedType) -> Type: | ||
return t | ||
|
||
|
@@ -490,6 +494,14 @@ def visit_callable_type(self, t: CallableType, nested: bool = True) -> Type: | |
variables=self.anal_var_defs(variables)) | ||
return ret | ||
|
||
def visit_overloaded(self, t: Overloaded) -> Type: | ||
# Overloaded types are manually constructed in semanal.py by analyzing the | ||
# AST and combining together the Callable types this visitor converts. | ||
# | ||
# So if we're ever asked to reanalyze an Overloaded type, we know it's | ||
# fine to just return it as-is. | ||
return t | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this is so different from |
||
|
||
def visit_tuple_type(self, t: TupleType) -> Type: | ||
# Types such as (t1, t2, ...) only allowed in assignment statements. They'll | ||
# generate errors elsewhere, and Tuple[t1, t2, ...] must be used instead. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Does it actually break some tests when you add a raise here?