Skip to content

Commit

Permalink
[mypyc] Fix ParamSpec (#17309)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Jun 3, 2024
1 parent 6c24ea6 commit aa4410f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mypyc/irbuild/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Type,
TypedDictType,
TypeType,
TypeVarType,
TypeVarLikeType,
UnboundType,
UninhabitedType,
UnionType,
Expand Down Expand Up @@ -131,7 +131,7 @@ def type_to_rtype(self, typ: Type | None) -> RType:
return object_rprimitive
elif isinstance(typ, TypeType):
return object_rprimitive
elif isinstance(typ, TypeVarType):
elif isinstance(typ, TypeVarLikeType):
# Erase type variable to upper bound.
# TODO: Erase to union if object has value restriction?
return self.type_to_rtype(typ.upper_bound)
Expand Down
41 changes: 41 additions & 0 deletions mypyc/test-data/irbuild-generics.test
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,44 @@ L2:
r4 = x
L3:
return r4


[case testParamSpec]
from typing import Callable, ParamSpec, TypeVar

P = ParamSpec("P")

def execute(func: Callable[P, int], *args: P.args, **kwargs: P.kwargs) -> int:
return func(*args, **kwargs)

def f(x: int) -> int:
return x

execute(f, 1)
[out]
def execute(func, args, kwargs):
func :: object
args :: tuple
kwargs :: dict
r0 :: list
r1 :: object
r2 :: dict
r3 :: i32
r4 :: bit
r5 :: tuple
r6 :: object
r7 :: int
L0:
r0 = PyList_New(0)
r1 = CPyList_Extend(r0, args)
r2 = PyDict_New()
r3 = CPyDict_UpdateInDisplay(r2, kwargs)
r4 = r3 >= 0 :: signed
r5 = PyList_AsTuple(r0)
r6 = PyObject_Call(func, r5, r2)
r7 = unbox(int, r6)
return r7
def f(x):
x :: int
L0:
return x

0 comments on commit aa4410f

Please sign in to comment.