Skip to content

Commit dfa0887

Browse files
committed
Recover Unpack sanity checks
1 parent d461ba2 commit dfa0887

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

mypy/typeanal.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,23 +1115,25 @@ def visit_callable_type(
11151115
kind = arg_kinds[i]
11161116
if kind == ARG_STAR:
11171117
pspec_with_args, at = self.anal_star_arg_type(ut, kind, nested=nested)
1118-
if nested and isinstance(at, UnpackType):
1119-
# TODO: it would be better to avoid this get_proper_type() call.
1120-
p_at = get_proper_type(at.type)
1121-
if isinstance(p_at, TypedDictType) and not at.from_star_syntax:
1122-
# Automatically detect Unpack[Foo] in Callable as backwards
1123-
# compatible syntax for **Foo, if Foo is a TypedDict.
1124-
at = p_at
1125-
unpacked_kwargs = True
1126-
arg_kinds[i] = ARG_STAR2
11271118
elif kind == ARG_STAR2:
11281119
pspec_with_kwargs, at = self.anal_star_arg_type(ut, kind, nested=nested)
11291120
else:
11301121
if pspec_with_args:
11311122
self.fail("Arguments not allowed after ParamSpec.args", t)
11321123
at = self.anal_type(ut, nested=nested, allow_unpack=False)
11331124
arg_types.append(at)
1134-
if nested:
1125+
1126+
if nested and arg_types:
1127+
last = arg_types[-1]
1128+
if isinstance(last, UnpackType):
1129+
# TODO: it would be better to avoid this get_proper_type() call.
1130+
p_at = get_proper_type(last.type)
1131+
if isinstance(p_at, TypedDictType) and not last.from_star_syntax:
1132+
# Automatically detect Unpack[Foo] in Callable as backwards
1133+
# compatible syntax for **Foo, if Foo is a TypedDict.
1134+
arg_kinds[-1] = ARG_STAR2
1135+
arg_types[-1] = p_at
1136+
unpacked_kwargs = True
11351137
arg_types = self.check_unpacks_in_list(arg_types)
11361138

11371139
if pspec_with_args != pspec_with_kwargs:

0 commit comments

Comments
 (0)