@@ -458,11 +458,30 @@ def pack_paramspec_args(self, an_args: Sequence[Type]) -> list[Type]:
458
458
# These do not support mypy_extensions VarArgs, etc. as they were already analyzed
459
459
# TODO: should these be re-analyzed to get rid of this inconsistency?
460
460
count = len (an_args )
461
- if count > 0 :
462
- first_arg = get_proper_type (an_args [0 ])
463
- if not (count == 1 and isinstance (first_arg , (Parameters , ParamSpecType , AnyType ))):
464
- return [Parameters (an_args , [ARG_POS ] * count , [None ] * count )]
465
- return list (an_args )
461
+ if count == 0 :
462
+ return []
463
+ if count == 1 and isinstance (get_proper_type (an_args [0 ]), AnyType ):
464
+ # Single Any is interpreted as ..., rather that a single argument with Any type.
465
+ # I didn't find this in the PEP, but it sounds reasonable.
466
+ return list (an_args )
467
+ if any (isinstance (a , (Parameters , ParamSpecType )) for a in an_args ):
468
+ if len (an_args ) > 1 :
469
+ first_wrong = next (
470
+ arg for arg in an_args if isinstance (arg , (Parameters , ParamSpecType ))
471
+ )
472
+ self .fail (
473
+ "Nested parameter specifications are not allowed" ,
474
+ first_wrong ,
475
+ code = codes .VALID_TYPE ,
476
+ )
477
+ return [AnyType (TypeOfAny .from_error )]
478
+ return list (an_args )
479
+ first = an_args [0 ]
480
+ return [
481
+ Parameters (
482
+ an_args , [ARG_POS ] * count , [None ] * count , line = first .line , column = first .column
483
+ )
484
+ ]
466
485
467
486
def cannot_resolve_type (self , t : UnboundType ) -> None :
468
487
# TODO: Move error message generation to messages.py. We'd first
@@ -503,7 +522,11 @@ def apply_concatenate_operator(self, t: UnboundType) -> Type:
503
522
names : list [str | None ] = [None ] * len (args )
504
523
505
524
pre = Parameters (
506
- args + pre .arg_types , [ARG_POS ] * len (args ) + pre .arg_kinds , names + pre .arg_names
525
+ args + pre .arg_types ,
526
+ [ARG_POS ] * len (args ) + pre .arg_kinds ,
527
+ names + pre .arg_names ,
528
+ line = t .line ,
529
+ column = t .column ,
507
530
)
508
531
return ps .copy_modified (prefix = pre ) if isinstance (ps , ParamSpecType ) else pre
509
532
@@ -913,7 +936,7 @@ def visit_type_list(self, t: TypeList) -> Type:
913
936
if params :
914
937
ts , kinds , names = params
915
938
# bind these types
916
- return Parameters (self .anal_array (ts ), kinds , names )
939
+ return Parameters (self .anal_array (ts ), kinds , names , line = t . line , column = t . column )
917
940
else :
918
941
return AnyType (TypeOfAny .from_error )
919
942
else :
0 commit comments