@@ -511,23 +511,31 @@ def _parameterized_type(self, base_type: Any, parameters):
511
511
raise ParseError ("[..., ...] not supported" )
512
512
return pytd .GenericType (base_type = base_type , parameters = (element_type ,))
513
513
else :
514
- parameters = tuple (pytd .AnythingType () if p is self .ELLIPSIS else p
515
- for p in parameters )
514
+ processed_parameters = []
515
+ # We do not yet support PEP 612, Parameter Specification Variables.
516
+ # To avoid blocking typeshed from adopting this PEP, we convert new
517
+ # features to approximations that only use supported features.
518
+ for p in parameters :
519
+ if p is self .ELLIPSIS :
520
+ processed = pytd .AnythingType ()
521
+ elif (p in self .param_specs and
522
+ self ._matches_full_name (base_type , "typing.Generic" )):
523
+ # Replacing a ParamSpec with a TypeVar isn't correct, but it'll work
524
+ # for simple cases in which the filled value is also a ParamSpec.
525
+ self .type_params .append (pytd .TypeParameter (p .name ))
526
+ processed = p
527
+ elif (p in self .param_specs or
528
+ (isinstance (p , pytd .GenericType ) and
529
+ self ._matches_full_name (p , _CONCATENATE_TYPES ))):
530
+ processed = pytd .AnythingType ()
531
+ else :
532
+ processed = p
533
+ processed_parameters .append (processed )
534
+ parameters = tuple (processed_parameters )
516
535
if self ._matches_named_type (base_type , _TUPLE_TYPES ):
517
536
return pytdgen .heterogeneous_tuple (base_type , parameters )
518
537
elif self ._matches_named_type (base_type , _CALLABLE_TYPES ):
519
- callable_parameters = []
520
- for p in parameters :
521
- # We do not yet support PEP 612, Parameter Specification Variables.
522
- # To avoid blocking typeshed from adopting this PEP, we convert new
523
- # features to Any.
524
- if p in self .param_specs or (
525
- isinstance (p , pytd .GenericType ) and
526
- self ._matches_full_name (p , _CONCATENATE_TYPES )):
527
- callable_parameters .append (pytd .AnythingType ())
528
- else :
529
- callable_parameters .append (p )
530
- return pytdgen .pytd_callable (base_type , tuple (callable_parameters ))
538
+ return pytdgen .pytd_callable (base_type , parameters )
531
539
else :
532
540
assert parameters
533
541
return pytd .GenericType (base_type = base_type , parameters = parameters )
@@ -558,7 +566,7 @@ def resolve_type(self, name: Union[str, pytd_node.Node]) -> pytd.Type:
558
566
def new_type (
559
567
self ,
560
568
name : Union [str , pytd_node .Node ],
561
- parameters : Optional [List [pytd_node . Node ]] = None
569
+ parameters : Optional [List [pytd . Type ]] = None
562
570
) -> pytd .Type :
563
571
"""Return the AST for a type.
564
572
0 commit comments