diff --git a/mypy/checker.py b/mypy/checker.py index cd02cccf8a47..e6d1048185ea 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -2810,7 +2810,7 @@ def infer_variable_type(self, name: Var, lvalue: Lvalue, def infer_partial_type(self, name: Var, lvalue: Lvalue, init_type: Type) -> bool: init_type = get_proper_type(init_type) if isinstance(init_type, NoneType): - partial_type = PartialType(None, name, [init_type]) + partial_type = PartialType(None, name) elif isinstance(init_type, Instance): fullname = init_type.type.fullname if (isinstance(lvalue, (NameExpr, MemberExpr)) and @@ -2820,7 +2820,7 @@ def infer_partial_type(self, name: Var, lvalue: Lvalue, init_type: Type) -> bool fullname == 'collections.OrderedDict') and all(isinstance(t, (NoneType, UninhabitedType)) for t in get_proper_types(init_type.args))): - partial_type = PartialType(init_type.type, name, init_type.args) + partial_type = PartialType(init_type.type, name) else: return False else: @@ -3018,15 +3018,11 @@ def try_infer_partial_type_from_indexed_assignment( # TODO: Don't infer things twice. key_type = self.expr_checker.accept(lvalue.index) value_type = self.expr_checker.accept(rvalue) - full_key_type = make_simplified_union( - [key_type, var.type.inner_types[0]]) - full_value_type = make_simplified_union( - [value_type, var.type.inner_types[1]]) - if (is_valid_inferred_type(full_key_type) and - is_valid_inferred_type(full_value_type)): + if (is_valid_inferred_type(key_type) and + is_valid_inferred_type(value_type)): if not self.current_node_deferred: var.type = self.named_generic_type(typename, - [full_key_type, full_value_type]) + [key_type, value_type]) del partial_types[var] def visit_expression_stmt(self, s: ExpressionStmt) -> None: @@ -4308,7 +4304,7 @@ def fixup_partial_type(self, typ: Type) -> Type: else: return Instance( typ.type, - [AnyType(TypeOfAny.unannotated) for _ in typ.inner_types]) + [AnyType(TypeOfAny.unannotated)] * len(typ.type.type_vars)) def is_defined_in_base_class(self, var: Var) -> bool: if var.info: diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index bb0c34b27ee8..692dc114a145 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -588,10 +588,8 @@ def try_infer_partial_type(self, e: CallExpr) -> None: if (typename in self.item_args and methodname in self.item_args[typename] and e.arg_kinds == [ARG_POS]): item_type = self.accept(e.args[0]) - full_item_type = make_simplified_union( - [item_type, partial_type.inner_types[0]]) - if mypy.checker.is_valid_inferred_type(full_item_type): - var.type = self.chk.named_generic_type(typename, [full_item_type]) + if mypy.checker.is_valid_inferred_type(item_type): + var.type = self.chk.named_generic_type(typename, [item_type]) del partial_types[var] elif (typename in self.container_args and methodname in self.container_args[typename] @@ -600,15 +598,10 @@ def try_infer_partial_type(self, e: CallExpr) -> None: if isinstance(arg_type, Instance): arg_typename = arg_type.type.fullname if arg_typename in self.container_args[typename][methodname]: - full_item_types = [ - make_simplified_union([item_type, prev_type]) - for item_type, prev_type - in zip(arg_type.args, partial_type.inner_types) - ] if all(mypy.checker.is_valid_inferred_type(item_type) - for item_type in full_item_types): + for item_type in arg_type.args): var.type = self.chk.named_generic_type(typename, - list(full_item_types)) + list(arg_type.args)) del partial_types[var] def apply_function_plugin(self, diff --git a/mypy/type_visitor.py b/mypy/type_visitor.py index da630e1f176c..b993f0d8a151 100644 --- a/mypy/type_visitor.py +++ b/mypy/type_visitor.py @@ -290,7 +290,7 @@ def visit_type_var(self, t: TypeVarType) -> T: return self.query_types([t.upper_bound] + t.values) def visit_partial_type(self, t: PartialType) -> T: - return self.query_types(t.inner_types) + return self.strategy([]) def visit_instance(self, t: Instance) -> T: return self.query_types(t.args) diff --git a/mypy/types.py b/mypy/types.py index 4734d8f0936c..22b15020c855 100644 --- a/mypy/types.py +++ b/mypy/types.py @@ -1761,16 +1761,13 @@ class PartialType(ProperType): # None for the 'None' partial type; otherwise a generic class type = None # type: Optional[mypy.nodes.TypeInfo] var = None # type: mypy.nodes.Var - inner_types = None # type: List[Type] def __init__(self, type: 'Optional[mypy.nodes.TypeInfo]', - var: 'mypy.nodes.Var', - inner_types: List[Type]) -> None: + var: 'mypy.nodes.Var') -> None: super().__init__() self.type = type self.var = var - self.inner_types = inner_types def accept(self, visitor: 'TypeVisitor[T]') -> T: return visitor.visit_partial_type(self)
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: