MCPcopy Create free account
hub / github.com/python/mypy / check_list_multiply

Method check_list_multiply

mypy/checkexpr.py:4446–4460  ·  view source on GitHub ↗

Type check an expression of form '[...] * e'. Type inference is special-cased for this common construct.

(self, e: OpExpr)

Source from the content-addressed store, hash-verified

4444 return make_simplified_union([restricted_left_type, right_type])
4445
4446 def check_list_multiply(self, e: OpExpr) -> Type:
4447 """Type check an expression of form '[...] * e'.
4448
4449 Type inference is special-cased for this common construct.
4450 """
4451 right_type = self.accept(e.right)
4452 if is_subtype(right_type, self.named_type("builtins.int")):
4453 # Special case: [...] * <int value>. Use the type context of the
4454 # OpExpr, since the multiplication does not affect the type.
4455 left_type = self.accept(e.left, type_context=self.type_context[-1])
4456 else:
4457 left_type = self.accept(e.left)
4458 result, method_type = self.check_op("__mul__", left_type, e.right, e)
4459 e.method_type = method_type
4460 return result
4461
4462 def visit_assignment_expr(self, e: AssignmentExpr) -> Type:
4463 value = self.accept(e.value)

Callers 1

visit_op_exprMethod · 0.95

Calls 4

acceptMethod · 0.95
named_typeMethod · 0.95
check_opMethod · 0.95
is_subtypeFunction · 0.90

Tested by

no test coverage detected