|
78 | 78 | typing_extensions_aliases, |
79 | 79 | EnumCallExpr, RUNTIME_PROTOCOL_DECOS, FakeExpression, Statement, AssignmentExpr, |
80 | 80 | ParamSpecExpr, EllipsisExpr, TypeVarLikeExpr, implicit_module_attrs, |
81 | | - MatchStmt, FuncBase |
| 81 | + MatchStmt, FuncBase, TypeVarTupleExpr |
82 | 82 | ) |
83 | 83 | from mypy.patterns import ( |
84 | 84 | AsPattern, OrPattern, ValuePattern, SequencePattern, |
@@ -2074,6 +2074,8 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None: |
2074 | 2074 | special_form = True |
2075 | 2075 | elif self.process_paramspec_declaration(s): |
2076 | 2076 | special_form = True |
| 2077 | + elif self.process_typevartuple_declaration(s): |
| 2078 | + special_form = True |
2077 | 2079 | # * type constructors |
2078 | 2080 | elif self.analyze_namedtuple_assign(s): |
2079 | 2081 | special_form = True |
@@ -3332,6 +3334,43 @@ def process_paramspec_declaration(self, s: AssignmentStmt) -> bool: |
3332 | 3334 | self.add_symbol(name, call.analyzed, s) |
3333 | 3335 | return True |
3334 | 3336 |
|
| 3337 | + def process_typevartuple_declaration(self, s: AssignmentStmt) -> bool: |
| 3338 | + """Checks if s declares a TypeVarTuple; if yes, store it in symbol table. |
| 3339 | +
|
| 3340 | + Return True if this looks like a TypeVarTuple (maybe with errors), otherwise return False. |
| 3341 | + """ |
| 3342 | + call = self.get_typevarlike_declaration( |
| 3343 | + s, ("typing_extensions.TypeVarTuple", "typing.TypeVarTuple") |
| 3344 | + ) |
| 3345 | + if not call: |
| 3346 | + return False |
| 3347 | + |
| 3348 | + if len(call.args) > 1: |
| 3349 | + self.fail( |
| 3350 | + "Only the first argument to TypeVarTuple has defined semantics", |
| 3351 | + s, |
| 3352 | + ) |
| 3353 | + |
| 3354 | + if not self.options.enable_incomplete_features: |
| 3355 | + self.fail('"TypeVarTuple" is not supported by mypy yet', s) |
| 3356 | + return False |
| 3357 | + |
| 3358 | + name = self.extract_typevarlike_name(s, call) |
| 3359 | + if name is None: |
| 3360 | + return False |
| 3361 | + |
| 3362 | + # PEP 646 does not specify the behavior of variance, constraints, or bounds. |
| 3363 | + if not call.analyzed: |
| 3364 | + typevartuple_var = TypeVarTupleExpr( |
| 3365 | + name, self.qualified_name(name), self.object_type(), INVARIANT |
| 3366 | + ) |
| 3367 | + typevartuple_var.line = call.line |
| 3368 | + call.analyzed = typevartuple_var |
| 3369 | + else: |
| 3370 | + assert isinstance(call.analyzed, TypeVarTupleExpr) |
| 3371 | + self.add_symbol(name, call.analyzed, s) |
| 3372 | + return True |
| 3373 | + |
3335 | 3374 | def basic_new_typeinfo(self, name: str, |
3336 | 3375 | basetype_or_fallback: Instance, |
3337 | 3376 | line: int) -> TypeInfo: |
|
0 commit comments