Skip to content

Commit 9df32fb

Browse files
h-joocopybara-github
authored andcommitted
Do not assert at this location. It is possible that the assertion triggers but pytype is indeed looking at a ParamSpec being passed in.
PiperOrigin-RevId: 754917442
1 parent 547024f commit 9df32fb

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pytype/matcher.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,14 +1198,18 @@ def _match_subst_against_subst(
11981198
type_param_map[t],
11991199
old_subst.copy(t=b1.AssignToNewVariable(self._node)),
12001200
)
1201-
else:
1202-
# If t isn't a TypeVar here it should be a ParamSpec
1201+
elif t in self._paramspecs:
12031202
assert t in self._paramspecs
12041203
new_var = self.ctx.program.NewVariable()
12051204
new_var.PasteBindingWithNewData(
12061205
b2, self.ctx.convert.get_maybe_abstract_instance(b2.data)
12071206
)
12081207
has_error = False
1208+
else:
1209+
new_var = self.ctx.program.NewVariable()
1210+
# Here' it's possibly a ParamSpec but the callpath to this code
1211+
# somehow does not assign to the self._paramspecs list.
1212+
has_error = False
12091213
# If new_subst contains a TypeVar that is mutually exclusive with t,
12101214
# then we can ignore this error because it is legal for t to not be
12111215
# present in new_subst.

pytype/tests/test_paramspec.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,25 @@ def f(x: int, y) -> Any: ...
611611
""",
612612
)
613613

614+
def test_paramspec_in_callable_as_param_not_fail(self):
615+
self.Check("""
616+
from typing import ParamSpec, Callable
617+
618+
_P = ParamSpec("_P")
619+
CallbleWithParamSpec = Callable[_P, None]
620+
621+
class A:
622+
def __init__(self, callable_1: CallbleWithParamSpec, callable_2: CallbleWithParamSpec):
623+
pass
624+
625+
class B(A):
626+
def __init__(self, callable_1: CallbleWithParamSpec, callable_2: CallbleWithParamSpec):
627+
super().__init__(
628+
callable_1,
629+
callable_2,
630+
)
631+
""")
632+
614633

615634
class ContextlibTest(test_base.BaseTest):
616635
"""Test some more complex uses of contextlib."""

0 commit comments

Comments
 (0)