diff --git a/mypy/checker.py b/mypy/checker.py index 9231cd73b0a6..22b3b1cded1f 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -7,12 +7,12 @@ import os.path from typing import ( - Any, Dict, Set, List, cast, Tuple, TypeVar, Union, Optional, NamedTuple + Any, Dict, Set, List, cast, Tuple, TypeVar, Union, Optional, NamedTuple, Mapping ) from mypy.errors import Errors, report_internal_error from mypy.nodes import ( - SymbolTable, Node, MypyFile, Var, Expression, + SymbolTable, Node, Statement, MypyFile, Var, Expression, OverloadedFuncDef, FuncDef, FuncItem, FuncBase, TypeInfo, ClassDef, GDEF, Block, AssignmentStmt, NameExpr, MemberExpr, IndexExpr, TupleExpr, ListExpr, ExpressionStmt, ReturnStmt, IfStmt, @@ -229,7 +229,7 @@ def accept(self, node: Node, type_context: Type = None) -> Type: else: return typ - def accept_loop(self, body: Node, else_body: Node = None) -> Type: + def accept_loop(self, body: Statement, else_body: Statement = None) -> Type: """Repeatedly type check a loop body until the frame doesn't change. Then check the else_body. @@ -1039,7 +1039,8 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> Type: for lv in s.lvalues[:-1]: self.check_assignment(lv, rvalue, s.type is None) - def check_assignment(self, lvalue: Node, rvalue: Node, infer_lvalue_type: bool = True) -> None: + def check_assignment(self, lvalue: Expression, rvalue: Expression, + infer_lvalue_type: bool = True) -> None: """Type check a single assignment: lvalue = rvalue.""" if isinstance(lvalue, TupleExpr) or isinstance(lvalue, ListExpr): self.check_assignment_to_multiple_lvalues(lvalue.items, rvalue, lvalue, @@ -1094,7 +1095,7 @@ def check_assignment(self, lvalue: Node, rvalue: Node, infer_lvalue_type: bool = self.infer_variable_type(inferred, lvalue, self.accept(rvalue), rvalue) - def check_assignment_to_multiple_lvalues(self, lvalues: List[Node], rvalue: Node, + def check_assignment_to_multiple_lvalues(self, lvalues: List[Expression], rvalue: Expression, context: Context, infer_lvalue_type: bool = True) -> None: if isinstance(rvalue, TupleExpr) or isinstance(rvalue, ListExpr): @@ -1129,7 +1130,7 @@ def check_assignment_to_multiple_lvalues(self, lvalues: List[Node], rvalue: Node else: self.check_multi_assignment(lvalues, rvalue, context, infer_lvalue_type) - def check_rvalue_count_in_assignment(self, lvalues: List[Node], rvalue_count: int, + def check_rvalue_count_in_assignment(self, lvalues: List[Expression], rvalue_count: int, context: Context) -> bool: if any(isinstance(lvalue, StarExpr) for lvalue in lvalues): if len(lvalues) - 1 > rvalue_count: @@ -1142,8 +1143,8 @@ def check_rvalue_count_in_assignment(self, lvalues: List[Node], rvalue_count: in return False return True - def check_multi_assignment(self, lvalues: List[Node], - rvalue: Node, + def check_multi_assignment(self, lvalues: List[Expression], + rvalue: Expression, context: Context, infer_lvalue_type: bool = True, msg: str = None) -> None: @@ -1165,7 +1166,7 @@ def check_multi_assignment(self, lvalues: List[Node], self.check_multi_assignment_from_iterable(lvalues, rvalue_type, context, infer_lvalue_type) - def check_multi_assignment_from_tuple(self, lvalues: List[Node], rvalue: Node, + def check_multi_assignment_from_tuple(self, lvalues: List[Expression], rvalue: Expression, rvalue_type: TupleType, context: Context, undefined_rvalue: bool, infer_lvalue_type: bool = True) -> None: @@ -1195,7 +1196,7 @@ def check_multi_assignment_from_tuple(self, lvalues: List[Node], rvalue: Node, for lv, rv_type in zip(right_lvs, right_rv_types): self.check_assignment(lv, self.temp_node(rv_type, context), infer_lvalue_type) - def lvalue_type_for_inference(self, lvalues: List[Node], rvalue_type: TupleType) -> Type: + def lvalue_type_for_inference(self, lvalues: List[Expression], rvalue_type: TupleType) -> Type: star_index = next((i for i, lv in enumerate(lvalues) if isinstance(lv, StarExpr)), len(lvalues)) left_lvs = lvalues[:star_index] @@ -1206,7 +1207,7 @@ def lvalue_type_for_inference(self, lvalues: List[Node], rvalue_type: TupleType) type_parameters = [] # type: List[Type] - def append_types_for_inference(lvs: List[Node], rv_types: List[Type]) -> None: + def append_types_for_inference(lvs: List[Expression], rv_types: List[Type]) -> None: for lv, rv_type in zip(lvs, rv_types): sub_lvalue_type, index_expr, inferred = self.check_lvalue(lv) if sub_lvalue_type: @@ -1251,7 +1252,7 @@ def type_is_iterable(self, type: Type) -> bool: [AnyType()])) and isinstance(type, Instance)) - def check_multi_assignment_from_iterable(self, lvalues: List[Node], rvalue_type: Type, + def check_multi_assignment_from_iterable(self, lvalues: List[Expression], rvalue_type: Type, context: Context, infer_lvalue_type: bool = True) -> None: if self.type_is_iterable(rvalue_type): @@ -1266,7 +1267,7 @@ def check_multi_assignment_from_iterable(self, lvalues: List[Node], rvalue_type: else: self.msg.type_not_iterable(rvalue_type, context) - def check_lvalue(self, lvalue: Node) -> Tuple[Type, IndexExpr, Var]: + def check_lvalue(self, lvalue: Expression) -> Tuple[Type, IndexExpr, Var]: lvalue_type = None # type: Type index_lvalue = None # type: IndexExpr inferred = None # type: Var @@ -1296,7 +1297,7 @@ def check_lvalue(self, lvalue: Node) -> Tuple[Type, IndexExpr, Var]: return lvalue_type, index_lvalue, inferred - def is_definition(self, s: Node) -> bool: + def is_definition(self, s: Expression) -> bool: if isinstance(s, NameExpr): if s.is_def: return True @@ -1312,7 +1313,7 @@ def is_definition(self, s: Node) -> bool: return s.is_def return False - def infer_variable_type(self, name: Var, lvalue: Node, + def infer_variable_type(self, name: Var, lvalue: Expression, init_type: Type, context: Context) -> None: """Infer the type of initialized variables from initializer type.""" if self.typing_mode_weak(): @@ -1339,7 +1340,7 @@ def infer_variable_type(self, name: Var, lvalue: Node, self.set_inferred_type(name, lvalue, init_type) - def infer_partial_type(self, name: Var, lvalue: Node, init_type: Type) -> bool: + def infer_partial_type(self, name: Var, lvalue: Expression, init_type: Type) -> bool: if isinstance(init_type, (NoneTyp, UninhabitedType)): partial_type = PartialType(None, name, [init_type]) elif isinstance(init_type, Instance): @@ -1358,7 +1359,7 @@ def infer_partial_type(self, name: Var, lvalue: Node, init_type: Type) -> bool: self.partial_types[-1][name] = lvalue return True - def set_inferred_type(self, var: Var, lvalue: Node, type: Type) -> None: + def set_inferred_type(self, var: Var, lvalue: Expression, type: Type) -> None: """Store inferred variable type. Store the type to both the variable node and the expression node that @@ -1368,7 +1369,7 @@ def set_inferred_type(self, var: Var, lvalue: Node, type: Type) -> None: var.type = type self.store_type(lvalue, type) - def set_inference_error_fallback_type(self, var: Var, lvalue: Node, type: Type, + def set_inference_error_fallback_type(self, var: Var, lvalue: Expression, type: Type, context: Context) -> None: """If errors on context line are ignored, store dummy type for variable. @@ -1383,7 +1384,7 @@ def set_inference_error_fallback_type(self, var: Var, lvalue: Node, type: Type, if context.get_line() in self.errors.ignored_lines[self.errors.file]: self.set_inferred_type(var, lvalue, AnyType()) - def narrow_type_from_binder(self, expr: Node, known_type: Type) -> Type: + def narrow_type_from_binder(self, expr: Expression, known_type: Type) -> Type: if expr.literal >= LITERAL_TYPE: restriction = self.binder.get(expr) if restriction: @@ -1391,8 +1392,8 @@ def narrow_type_from_binder(self, expr: Node, known_type: Type) -> Type: return ans return known_type - def check_simple_assignment(self, lvalue_type: Type, rvalue: Node, - context: Node, + def check_simple_assignment(self, lvalue_type: Type, rvalue: Expression, + context: Union[Expression, ImportBase], msg: str = messages.INCOMPATIBLE_TYPES_IN_ASSIGNMENT, lvalue_name: str = 'variable', rvalue_name: str = 'expression') -> Type: @@ -1414,7 +1415,7 @@ def check_simple_assignment(self, lvalue_type: Type, rvalue: Node, return rvalue_type def check_indexed_assignment(self, lvalue: IndexExpr, - rvalue: Node, context: Context) -> None: + rvalue: Expression, context: Context) -> None: """Type check indexed assignment base[index] = rvalue. The lvalue argument is the base[index] expression. @@ -1429,7 +1430,7 @@ def check_indexed_assignment(self, lvalue: IndexExpr, context) def try_infer_partial_type_from_indexed_assignment( - self, lvalue: IndexExpr, rvalue: Node) -> None: + self, lvalue: IndexExpr, rvalue: Expression) -> None: # TODO: Should we share some of this with try_infer_partial_type? if isinstance(lvalue.base, RefExpr) and isinstance(lvalue.base.node, Var): var = lvalue.base.node @@ -1610,7 +1611,7 @@ def visit_raise_stmt(self, s: RaiseStmt) -> Type: if s.from_expr: self.type_check_raise(s.from_expr, s) - def type_check_raise(self, e: Node, s: RaiseStmt) -> None: + def type_check_raise(self, e: Expression, s: RaiseStmt) -> None: typ = self.accept(e) if isinstance(typ, FunctionLike): if typ.is_type_obj(): @@ -1701,7 +1702,7 @@ def visit_try_without_finally(self, s: TryStmt) -> bool: breaking_out = breaking_out and self.binder.last_pop_breaking_out return breaking_out - def visit_except_handler_test(self, n: Node) -> Type: + def visit_except_handler_test(self, n: Expression) -> Type: """Type check an exception handler test clause.""" type = self.accept(n) @@ -1737,7 +1738,7 @@ def visit_for_stmt(self, s: ForStmt) -> Type: self.analyze_index_variables(s.index, item_type, s) self.accept_loop(s.body, s.else_body) - def analyze_async_iterable_item_type(self, expr: Node) -> Type: + def analyze_async_iterable_item_type(self, expr: Expression) -> Type: """Analyse async iterable expression and return iterator item type.""" iterable = self.accept(expr) @@ -1756,7 +1757,7 @@ def analyze_async_iterable_item_type(self, expr: Node) -> Type: return self.check_awaitable_expr(awaitable, expr, messages.INCOMPATIBLE_TYPES_IN_ASYNC_FOR) - def analyze_iterable_item_type(self, expr: Node) -> Type: + def analyze_iterable_item_type(self, expr: Expression) -> Type: """Analyse iterable expression and return iterator item type.""" iterable = self.accept(expr) @@ -1791,7 +1792,7 @@ def analyze_iterable_item_type(self, expr: Node) -> Type: expr) return echk.check_call(method, [], [], expr)[0] - def analyze_index_variables(self, index: Node, item_type: Type, + def analyze_index_variables(self, index: Expression, item_type: Type, context: Context) -> None: """Type check or infer for loop or list comprehension index vars.""" self.check_assignment(index, self.temp_node(item_type, context)) @@ -1805,7 +1806,7 @@ def visit_del_stmt(self, s: DelStmt) -> Type: c.line = s.line return c.accept(self) else: - def flatten(t: Node) -> List[Node]: + def flatten(t: Expression) -> List[Expression]: """Flatten a nested sequence of tuples/lists into one list of nodes.""" if isinstance(t, TupleExpr) or isinstance(t, ListExpr): return [b for a in t.items for b in flatten(a)] @@ -2330,7 +2331,7 @@ def check_usable_type(self, typ: Type, context: Context) -> None: if self.is_unusable_type(typ): self.msg.does_not_return_value(typ, context) - def temp_node(self, t: Type, context: Context = None) -> Node: + def temp_node(self, t: Type, context: Context = None) -> Expression: """Create a temporary node with the given, fixed type.""" temp = TempNode(t) if context: @@ -2368,12 +2369,10 @@ def method_type(self, func: FuncBase) -> FunctionLike: # probably be better to have the dict keyed by the nodes' literal_hash # field instead. -# NB: This should be `TypeMap = Optional[Dict[Node, Type]]`! -# But see https://github.com/python/mypy/issues/1637 -TypeMap = Dict[Node, Type] +TypeMap = Optional[Dict[Expression, Type]] -def conditional_type_map(expr: Node, +def conditional_type_map(expr: Expression, current_type: Optional[Type], proposed_type: Optional[Type], *, @@ -2405,7 +2404,7 @@ def conditional_type_map(expr: Node, return {}, {} -def is_literal_none(n: Node) -> bool: +def is_literal_none(n: Expression) -> bool: return isinstance(n, NameExpr) and n.fullname == 'builtins.None' @@ -2453,8 +2452,8 @@ def or_conditional_maps(m1: TypeMap, m2: TypeMap) -> TypeMap: return result -def find_isinstance_check(node: Node, - type_map: Dict[Node, Type], +def find_isinstance_check(node: Expression, + type_map: Mapping[Node, Type], weak: bool=False ) -> Tuple[TypeMap, TypeMap]: """Find any isinstance checks (within a chain of ands). Includes @@ -2473,15 +2472,15 @@ def find_isinstance_check(node: Node, expr = node.args[0] if expr.literal == LITERAL_TYPE: vartype = type_map[expr] - type = get_isinstance_type(node.args[1], type_map) + type = get_isinstance_type(node.args[1], type_map[node.args[1]]) return conditional_type_map(expr, vartype, type, weak=weak) elif (isinstance(node, ComparisonExpr) and any(is_literal_none(n) for n in node.operands) and experiments.STRICT_OPTIONAL): # Check for `x is None` and `x is not None`. is_not = node.operators == ['is not'] if is_not or node.operators == ['is']: - if_vars = {} # type: Dict[Node, Type] - else_vars = {} # type: Dict[Node, Type] + if_vars = {} # type: Dict[Expression, Type] + else_vars = {} # type: Dict[Expression, Type] for expr in node.operands: if expr.literal == LITERAL_TYPE and not is_literal_none(expr) and expr in type_map: # This should only be true at most once: there should be @@ -2500,7 +2499,7 @@ def find_isinstance_check(node: Node, vartype = type_map[node] if_type = true_only(vartype) else_type = false_only(vartype) - ref = node # type: Node + ref = node # type: Expression if_map = {ref: if_type} if not isinstance(if_type, UninhabitedType) else None else_map = {ref: else_type} if not isinstance(else_type, UninhabitedType) else None return if_map, else_map @@ -2546,9 +2545,7 @@ def find_isinstance_check(node: Node, return {}, {} -def get_isinstance_type(node: Node, type_map: Dict[Node, Type]) -> Type: - type = type_map[node] - +def get_isinstance_type(node: Expression, type: Type) -> Type: if isinstance(type, TupleType): all_types = type.items else: @@ -2573,7 +2570,7 @@ def get_isinstance_type(node: Node, type_map: Dict[Node, Type]) -> Type: return UnionType(types) -def expand_node(defn: Node, map: Dict[TypeVarId, Type]) -> Node: +def expand_node(defn: FuncItem, map: Dict[TypeVarId, Type]) -> Node: visitor = TypeTransformVisitor(map) return defn.accept(visitor) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 178a21429a73..e0a54ef6a558 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -10,7 +10,7 @@ ) from mypy.nodes import ( NameExpr, RefExpr, Var, FuncDef, OverloadedFuncDef, TypeInfo, CallExpr, - Node, MemberExpr, IntExpr, StrExpr, BytesExpr, UnicodeExpr, FloatExpr, + Expression, MemberExpr, IntExpr, StrExpr, BytesExpr, UnicodeExpr, FloatExpr, OpExpr, UnaryExpr, IndexExpr, CastExpr, RevealTypeExpr, TypeApplication, ListExpr, TupleExpr, DictExpr, FuncExpr, SuperExpr, SliceExpr, Context, ListComprehension, GeneratorExpr, SetExpr, MypyFile, Decorator, @@ -234,10 +234,10 @@ def check_call_expr_with_callee_type(self, callee_type: Type, return self.check_call(callee_type, e.args, e.arg_kinds, e, e.arg_names, callable_node=e.callee)[0] - def check_call(self, callee: Type, args: List[Node], + def check_call(self, callee: Type, args: List[Expression], arg_kinds: List[int], context: Context, arg_names: List[str] = None, - callable_node: Node = None, + callable_node: Expression = None, arg_messages: MessageBuilder = None) -> Tuple[Type, Type]: """Type check a call. @@ -370,7 +370,7 @@ def analyze_type_type_callee(self, item: Type, context: Context) -> Type: return AnyType() def infer_arg_types_in_context(self, callee: Optional[CallableType], - args: List[Node]) -> List[Type]: + args: List[Expression]) -> List[Type]: """Infer argument expression types using a callable type as context. For example, if callee argument 2 has type List[int], infer the @@ -402,7 +402,7 @@ def infer_arg_types_in_context(self, callee: Optional[CallableType], return res def infer_arg_types_in_context2( - self, callee: CallableType, args: List[Node], arg_kinds: List[int], + self, callee: CallableType, args: List[Expression], arg_kinds: List[int], formal_to_actual: List[List[int]]) -> List[Type]: """Infer argument expression types using a callable type as context. @@ -468,7 +468,7 @@ def infer_function_type_arguments_using_context( error_context)) def infer_function_type_arguments(self, callee_type: CallableType, - args: List[Node], + args: List[Expression], arg_kinds: List[int], formal_to_actual: List[List[int]], context: Context) -> CallableType: @@ -533,7 +533,7 @@ def infer_function_type_arguments(self, callee_type: CallableType, def infer_function_type_arguments_pass2( self, callee_type: CallableType, - args: List[Node], + args: List[Expression], arg_kinds: List[int], formal_to_actual: List[List[int]], inferred_args: List[Type], @@ -1048,7 +1048,7 @@ def get_operator_method(self, op: str) -> str: else: return nodes.op_methods[op] - def _check_op_for_errors(self, method: str, base_type: Type, arg: Node, + def _check_op_for_errors(self, method: str, base_type: Type, arg: Expression, context: Context ) -> Tuple[Tuple[Type, Type], MessageBuilder]: """Type check a binary operation which maps to a method call. @@ -1062,7 +1062,7 @@ def _check_op_for_errors(self, method: str, base_type: Type, arg: Node, local_errors) return result, local_errors - def check_op_local(self, method: str, base_type: Type, arg: Node, + def check_op_local(self, method: str, base_type: Type, arg: Expression, context: Context, local_errors: MessageBuilder) -> Tuple[Type, Type]: """Type check a binary operation which maps to a method call. @@ -1074,7 +1074,7 @@ def check_op_local(self, method: str, base_type: Type, arg: Node, return self.check_call(method_type, [arg], [nodes.ARG_POS], context, arg_messages=local_errors) - def check_op(self, method: str, base_type: Type, arg: Node, + def check_op(self, method: str, base_type: Type, arg: Expression, context: Context, allow_reverse: bool = False) -> Tuple[Type, Type]: """Type check a binary operation which maps to a method call. @@ -1336,7 +1336,7 @@ def visit_tuple_slice_helper(self, left_type: TupleType, slic: SliceExpr) -> Typ return left_type.slice(begin, stride, end) - def _get_value(self, index: Node) -> Optional[int]: + def _get_value(self, index: Expression) -> Optional[int]: if isinstance(index, IntExpr): return index.value elif isinstance(index, UnaryExpr): @@ -1383,7 +1383,7 @@ def visit_list_expr(self, e: ListExpr) -> Type: def visit_set_expr(self, e: SetExpr) -> Type: return self.check_lst_expr(e.items, 'builtins.set', '', e) - def check_lst_expr(self, items: List[Node], fullname: str, + def check_lst_expr(self, items: List[Expression], fullname: str, tag: str, context: Context) -> Type: # Translate into type checking a generic function call. # Used for list and set expressions, as well as for tuples @@ -1472,8 +1472,8 @@ def visit_dict_expr(self, e: DictExpr) -> Type: Translate it into a call to dict(), with provisions for **expr. """ # Collect function arguments, watching out for **expr. - args = [] # type: List[Node] # Regular "key: value" - stargs = [] # type: List[Node] # For "**expr" + args = [] # type: List[Expression] # Regular "key: value" + stargs = [] # type: List[Expression] # For "**expr" for key, value in e.items: if key is None: stargs.append(value) @@ -1734,8 +1734,8 @@ def visit_conditional_expr(self, e: ConditionalExpr) -> Type: return res - def analyze_cond_branch(self, map: Optional[Dict[Node, Type]], - node: Node, context: Optional[Type]) -> Type: + def analyze_cond_branch(self, map: Optional[Dict[Expression, Type]], + node: Expression, context: Optional[Type]) -> Type: with self.chk.binder.frame_context(): if map: for var, type in map.items(): @@ -1750,7 +1750,7 @@ def visit_backquote_expr(self, e: BackquoteExpr) -> Type: # Helpers # - def accept(self, node: Node, context: Type = None) -> Type: + def accept(self, node: Expression, context: Type = None) -> Type: """Type check a node. Alias for TypeChecker.accept.""" return self.chk.accept(node, context) diff --git a/mypy/nodes.py b/mypy/nodes.py index d989cf680f9c..d243c6b10611 100644 --- a/mypy/nodes.py +++ b/mypy/nodes.py @@ -1,8 +1,7 @@ """Abstract syntax tree node classes (i.e. parse tree).""" import os -import re -from abc import abstractmethod, ABCMeta +from abc import abstractmethod from typing import ( Any, TypeVar, List, Tuple, cast, Set, Dict, Union, Optional @@ -284,7 +283,7 @@ class FuncBase(SymbolNode): """Abstract base class for function-like nodes""" # Type signature. This is usually CallableType or Overloaded, but it can be something else for - # decorated functions/ + # decorated functions type = None # type: mypy.types.Type # If method, reference to TypeInfo info = None # type: TypeInfo @@ -345,7 +344,7 @@ class Argument(Node): variable = None # type: Var type_annotation = None # type: Optional[mypy.types.Type] - initializater = None # type: Optional[Expression] + initializer = None # type: Optional[Expression] kind = None # type: int initialization_statement = None # type: Optional[AssignmentStmt] @@ -572,7 +571,7 @@ def deserialize(cls, data: JsonDict) -> 'Decorator': return dec -class Var(SymbolNode, Statement): +class Var(SymbolNode, Node): """A variable. It can refer to global/local variable or a data attribute. @@ -1737,12 +1736,12 @@ def accept(self, visitor: NodeVisitor[T]) -> T: return visitor.visit_newtype_expr(self) -class AwaitExpr(Node): +class AwaitExpr(Expression): """Await expression (await ...).""" - expr = None # type: Node + expr = None # type: Expression - def __init__(self, expr: Node) -> None: + def __init__(self, expr: Expression) -> None: self.expr = expr def accept(self, visitor: NodeVisitor[T]) -> T: diff --git a/mypy/semanal.py b/mypy/semanal.py index eb81f1878d08..02fd0e082b74 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -44,13 +44,13 @@ """ from typing import ( - List, Dict, Set, Tuple, cast, Any, TypeVar, Union, Optional, Callable + List, Dict, Set, Tuple, cast, Any, TypeVar, Union, Optional, Callable, Iterable ) from mypy.nodes import ( MypyFile, TypeInfo, Node, AssignmentStmt, FuncDef, OverloadedFuncDef, ClassDef, Var, GDEF, MODULE_REF, FuncItem, Import, - ImportFrom, ImportAll, Block, LDEF, NameExpr, MemberExpr, + ImportFrom, ImportAll, Block, LDEF, NameExpr, MemberExpr, Expression, IndexExpr, TupleExpr, ListExpr, ExpressionStmt, ReturnStmt, RaiseStmt, AssertStmt, OperatorAssignmentStmt, WhileStmt, ForStmt, BreakStmt, ContinueStmt, IfStmt, TryStmt, WithStmt, DelStmt, @@ -1361,7 +1361,8 @@ def process_newtype_declaration(self, s: AssignmentStmt) -> None: # TODO: why does NewType work in local scopes despite always being of kind GDEF? node.kind = GDEF node.node = newtype_class_info - call.analyzed = NewTypeExpr(newtype_class_info).set_line(call.line) + call.analyzed = NewTypeExpr(newtype_class_info) + call.analyzed.set_line(call.line) def analyze_newtype_declaration(self, s: AssignmentStmt) -> Tuple[Optional[str], Optional[CallExpr]]: @@ -1384,7 +1385,8 @@ def analyze_newtype_declaration(self, # overwritten later with a fully complete NewTypeExpr if there are no other # errors with the NewType() call. call = s.rvalue - call.analyzed = NewTypeExpr(None).set_line(call.line) + call.analyzed = NewTypeExpr(None) + call.analyzed.set_line(call.line) return name, call @@ -1505,7 +1507,7 @@ def get_typevar_declaration(self, s: AssignmentStmt) -> Optional[CallExpr]: return None return call - def process_typevar_parameters(self, args: List[Node], + def process_typevar_parameters(self, args: List[Expression], names: List[Optional[str]], kinds: List[int], has_values: bool, @@ -1614,7 +1616,8 @@ def check_namedtuple(self, node: Node, var_name: str = None) -> TypeInfo: info = self.build_namedtuple_typeinfo(name, items, types) # Store it as a global just in case it would remain anonymous. self.globals[name] = SymbolTableNode(GDEF, info, self.cur_mod_id) - call.analyzed = NamedTupleExpr(info).set_line(call.line) + call.analyzed = NamedTupleExpr(info) + call.analyzed.set_line(call.line) return info def parse_namedtuple_args(self, call: CallExpr, @@ -1661,7 +1664,7 @@ def parse_namedtuple_args(self, call: CallExpr, + ', '.join(underscore), call) return items, types, ok - def parse_namedtuple_fields_with_types(self, nodes: List[Node], + def parse_namedtuple_fields_with_types(self, nodes: List[Expression], context: Context) -> Tuple[List[str], List[Type], bool]: items = [] # type: List[str] types = [] # type: List[Type] @@ -1766,7 +1769,7 @@ def add_method(funcname: str, ret: Type, args: List[Argument], name=None, def make_argument(self, name: str, type: Type) -> Argument: return Argument(Var(name), type, None, ARG_POS) - def analyze_types(self, items: List[Node]) -> List[Type]: + def analyze_types(self, items: Iterable[Node]) -> List[Type]: result = [] # type: List[Type] for node in items: try: