Skip to content

Refactor: remove unused attribute from PartialType #8078

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 1 commit into from
Dec 5, 2019
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
16 changes: 6 additions & 10 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 4 additions & 11 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion mypy/type_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy