Skip to content

Commit e8dcf88

Browse files
check paramspec flavor
1 parent 68bc671 commit e8dcf88

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

mypy/argmap.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
AnyType,
1414
CallableType,
1515
Instance,
16+
ParamSpecFlavor,
1617
ParamSpecType,
1718
ProperType,
1819
TupleType,
@@ -245,6 +246,9 @@ def expand_actual_type(
245246
return item
246247
elif isinstance(star_args_type, ParamSpecType):
247248
# 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}"
248252
return star_args_type
249253
else:
250254
return AnyType(TypeOfAny.from_error)
@@ -386,12 +390,17 @@ def parse_star_args_type(
386390
) -> TupleType | IterableType | ParamSpecType | AnyType:
387391
"""Parse the type of a ``*args`` argument.
388392
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.
390395
"""
391396
p_t = get_proper_type(typ)
392-
if isinstance(p_t, (TupleType, ParamSpecType, AnyType)):
397+
if isinstance(p_t, (TupleType, AnyType)):
393398
# just return the type as-is
394399
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)
395404
elif isinstance(p_t, TypeVarTupleType):
396405
return self.parse_star_args_type(p_t.upper_bound)
397406
elif isinstance(p_t, UnionType):

0 commit comments

Comments
 (0)