MCPcopy Index your code
hub / github.com/python/mypy / tuple_context_matches

Method tuple_context_matches

mypy/checkexpr.py:5260–5271  ·  view source on GitHub ↗
(self, expr: TupleExpr, ctx: TupleType)

Source from the content-addressed store, hash-verified

5258 return remove_instance_last_known_values(out)
5259
5260 def tuple_context_matches(self, expr: TupleExpr, ctx: TupleType) -> bool:
5261 ctx_unpack_index = find_unpack_in_list(ctx.items)
5262 if ctx_unpack_index is None:
5263 # For fixed tuples accept everything that can possibly match, even if this
5264 # requires all star items to be empty.
5265 return len([e for e in expr.items if not isinstance(e, StarExpr)]) <= len(ctx.items)
5266 # For variadic context, the only easy case is when structure matches exactly.
5267 # TODO: try using tuple type context in more cases.
5268 if len([e for e in expr.items if isinstance(e, StarExpr)]) != 1:
5269 return False
5270 expr_star_index = next(i for i, lv in enumerate(expr.items) if isinstance(lv, StarExpr))
5271 return len(expr.items) == len(ctx.items) and ctx_unpack_index == expr_star_index
5272
5273 def visit_tuple_expr(self, e: TupleExpr) -> Type:
5274 """Type check a tuple expression."""

Callers 1

visit_tuple_exprMethod · 0.95

Calls 5

find_unpack_in_listFunction · 0.90
lenFunction · 0.85
isinstanceFunction · 0.85
nextFunction · 0.85
enumerateFunction · 0.85

Tested by

no test coverage detected