|
13 | 13 | AnyType,
|
14 | 14 | CallableType,
|
15 | 15 | Instance,
|
| 16 | + ParamSpecFlavor, |
16 | 17 | ParamSpecType,
|
17 | 18 | ProperType,
|
18 | 19 | TupleType,
|
@@ -245,6 +246,9 @@ def expand_actual_type(
|
245 | 246 | return item
|
246 | 247 | elif isinstance(star_args_type, ParamSpecType):
|
247 | 248 | # ParamSpec is valid in *args but it can't be unpacked.
|
| 249 | + assert ( |
| 250 | + star_args_type.flavor == ParamSpecFlavor.ARGS |
| 251 | + ), f"ParamSpecType for *args should have ARGS flavor, got {star_args_type.flavor}" |
248 | 252 | return star_args_type
|
249 | 253 | else:
|
250 | 254 | return AnyType(TypeOfAny.from_error)
|
@@ -386,12 +390,17 @@ def parse_star_args_type(
|
386 | 390 | ) -> TupleType | IterableType | ParamSpecType | AnyType:
|
387 | 391 | """Parse the type of a ``*args`` argument.
|
388 | 392 |
|
389 |
| - Returns one of TupleType, TupleInstance or AnyType. |
| 393 | + Returns one of TupleType, IterableType, ParamSpecType (ARGS flavor), |
| 394 | + or AnyType(TypeOfAny.from_error) if the type cannot be parsed or is invalid. |
390 | 395 | """
|
391 | 396 | p_t = get_proper_type(typ)
|
392 |
| - if isinstance(p_t, (TupleType, ParamSpecType, AnyType)): |
| 397 | + if isinstance(p_t, (TupleType, AnyType)): |
393 | 398 | # just return the type as-is
|
394 | 399 | return p_t
|
| 400 | + elif isinstance(p_t, ParamSpecType): |
| 401 | + if p_t.flavor == ParamSpecFlavor.ARGS: |
| 402 | + return p_t |
| 403 | + return AnyType(TypeOfAny.from_error) |
395 | 404 | elif isinstance(p_t, TypeVarTupleType):
|
396 | 405 | return self.parse_star_args_type(p_t.upper_bound)
|
397 | 406 | elif isinstance(p_t, UnionType):
|
|
0 commit comments