8000 Reject invalid ParamSpec locations by sterliakov · Pull Request #18278 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Reject invalid ParamSpec locations #18278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Prev Previous commit
Next Next commit
Recover Unpack sanity checks
  • Loading branch information
sterliakov committed Dec 11, 2024
commit dfa08879085005314e36a1b6fbe0626f0f3e8bcc
22 changes: 12 additions & 10 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,23 +1115,25 @@ def visit_callable_type(
kind = arg_kinds[i]
if kind == ARG_STAR:
pspec_with_args, at = self.anal_star_arg_type(ut, kind, nested=nested)
if nested and isinstance(at, UnpackType):
# TODO: it would be better to avoid this get_proper_type() call.
p_at = get_proper_type(at.type)
if isinstance(p_at, TypedDictType) and not at.from_star_syntax:
# Automatically detect Unpack[Foo] in Callable as backwards
# compatible syntax for **Foo, if Foo is a TypedDict.
at = p_at
unpacked_kwargs = True
arg_kinds[i] = ARG_STAR2
elif kind == ARG_STAR2:
pspec_with_kwargs, at = self.anal_star_arg_type(ut, kind, nested=nested)
else:
if pspec_with_args:
self.fail("Arguments not allowed after ParamSpec.args", t)
at = self.anal_type(ut, nested=nested, allow_unpack=False)
arg_types.append(at)
if nested:

if nested and arg_types:
last = arg_types[-1]
if isinstance(last, UnpackType):
# TODO: it would be better to avoid this get_proper_type() call.
p_at = get_proper_type(last.type)
if isinstance(p_at, TypedDictType) and not last.from_star_syntax:
# Automatically detect Unpack[Foo] in Callable as backwards
# compatible syntax for **Foo, if Foo is a TypedDict.
arg_kinds[-1] = ARG_STAR2
arg_types[-1] = p_at
unpacked_kwargs = True
arg_types = self.check_unpacks_in_list(arg_types)

if pspec_with_args != pspec_with_kwargs:
Expand Down
0