Skip to content

Commit aa4410f

Browse files
authored
[mypyc] Fix ParamSpec (#17309)
Fixes mypyc/mypyc#1051
1 parent 6c24ea6 commit aa4410f

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

mypyc/irbuild/mapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Type,
1616
TypedDictType,
1717
TypeType,
18-
TypeVarType,
18+
TypeVarLikeType,
1919
UnboundType,
2020
UninhabitedType,
2121
UnionType,
@@ -131,7 +131,7 @@ def type_to_rtype(self, typ: Type | None) -> RType:
131131
return object_rprimitive
132132
elif isinstance(typ, TypeType):
133133
return object_rprimitive
134-
elif isinstance(typ, TypeVarType):
134+
elif isinstance(typ, TypeVarLikeType):
135135
# Erase type variable to upper bound.
136136
# TODO: Erase to union if object has value restriction?
137137
return self.type_to_rtype(typ.upper_bound)

mypyc/test-data/irbuild-generics.test

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,44 @@ L2:
148148
r4 = x
149149
L3:
150150
return r4
151+
152+
153+
[case testParamSpec]
154+
from typing import Callable, ParamSpec, TypeVar
155+
156+
P = ParamSpec("P")
157+
158+
def execute(func: Callable[P, int], *args: P.args, **kwargs: P.kwargs) -> int:
159+
return func(*args, **kwargs)
160+
161+
def f(x: int) -> int:
162+
return x
163+
164+
execute(f, 1)
165+
[out]
166+
def execute(func, args, kwargs):
167+
func :: object
168+
args :: tuple
169+
kwargs :: dict
170+
r0 :: list
171+
r1 :: object
172+
r2 :: dict
173+
r3 :: i32
174+
r4 :: bit
175+
r5 :: tuple
176+
r6 :: object
177+
r7 :: int
178+
L0:
179+
r0 = PyList_New(0)
180+
r1 = CPyList_Extend(r0, args)
181+
r2 = PyDict_New()
182+
r3 = CPyDict_UpdateInDisplay(r2, kwargs)
183+
r4 = r3 >= 0 :: signed
184+
r5 = PyList_AsTuple(r0)
185+
r6 = PyObject_Call(func, r5, r2)
186+
r7 = unbox(int, r6)
187+
return r7
188+
def f(x):
189+
x :: int
190+
L0:
191+
return x

0 commit comments

Comments
 (0)