Skip to content
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

[mypyc] Fix ParamSpec #17309

Merged
merged 3 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading