@@ -166,6 +166,29 @@ def no_subscript_builtin_alias(name: str, propose_alt: bool = True) -> str:
166
166
return msg
167
167
168
168
169
+ def pack_paramspec_args (an_args : Sequence [Type ]) -> list [Type ]:
170
+ # "Aesthetic" ParamSpec literals for single ParamSpec: C[int, str] -> C[[int, str]].
171
+ # These do not support mypy_extensions VarArgs, etc. as they were already analyzed
172
+ # TODO: should these be re-analyzed to get rid of this inconsistency?
173
+ count = len (an_args )
174
+ if count > 0 :
175
+ first_arg = get_proper_type (an_args [0 ])
176
+ if not (count == 1 and isinstance (first_arg , (Parameters , ParamSpecType ))):
177
+ if isinstance (first_arg , AnyType ) and first_arg .type_of_any == TypeOfAny .from_error :
178
+ # Question: should I make new AnyTypes instead of reusing them?
179
+ return [
180
+ Parameters (
181
+ [first_arg , first_arg ],
182
+ [ARG_STAR , ARG_STAR2 ],
183
+ [None , None ],
184
+ is_ellipsis_args = True ,
185
+ )
186
+ ]
187
+ else :
188
+ return [Parameters (an_args , [ARG_POS ] * count , [None ] * count )]
189
+ return list (an_args )
190
+
191
+
169
192
class TypeAnalyser (SyntheticTypeVisitor [Type ], TypeAnalyzerPluginInterface ):
170
193
"""Semantic analyzer for types.
171
194
@@ -395,7 +418,7 @@ def visit_unbound_type_nonoptional(self, t: UnboundType, defining_literal: bool)
395
418
allow_param_spec_literals = node .has_param_spec_type ,
396
419
)
397
420
if node .has_param_spec_type and len (node .alias_tvars ) == 1 :
398
- an_args = self . pack_paramspec_args (an_args )
421
+ an_args = pack_paramspec_args (an_args )
399
422
400
423
disallow_any = self .options .disallow_any_generics and not self .is_typeshed_stub
401
424
res = instantiate_type_alias (
@@ -440,17 +463,6 @@ def visit_unbound_type_nonoptional(self, t: UnboundType, defining_literal: bool)
440
463
else : # sym is None
441
464
return AnyType (TypeOfAny .special_form )
442
465
443
- def pack_paramspec_args (self , an_args : Sequence [Type ]) -> list [Type ]:
444
- # "Aesthetic" ParamSpec literals for single ParamSpec: C[int, str] -> C[[int, str]].
445
- # These do not support mypy_extensions VarArgs, etc. as they were already analyzed
446
- # TODO: should these be re-analyzed to get rid of this inconsistency?
447
- count = len (an_args )
448
- if count > 0 :
449
- first_arg = get_proper_type (an_args [0 ])
450
- if not (count == 1 and isinstance (first_arg , (Parameters , ParamSpecType , AnyType ))):
451
- return [Parameters (an_args , [ARG_POS ] * count , [None ] * count )]
452
- return list (an_args )
453
-
454
466
def cannot_resolve_type (self , t : UnboundType ) -> None :
455
467
# TODO: Move error message generation to messages.py. We'd first
456
468
# need access to MessageBuilder here. Also move the similar
@@ -686,7 +698,7 @@ def analyze_type_with_type_info(
686
698
ctx .column ,
687
699
)
688
700
if len (info .type_vars ) == 1 and info .has_param_spec_type :
689
- instance .args = tuple (self . pack_paramspec_args (instance .args ))
701
+ instance .args = tuple (pack_paramspec_args (instance .args ))
690
702
691
703
if info .has_type_var_tuple_type :
692
704
if instance .args :
0 commit comments