(self, expr: TupleExpr, ctx: TupleType)
| 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.""" |
no test coverage detected