Skip to content
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
33 changes: 33 additions & 0 deletions pytype/tests/test_typevar1.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,39 @@ def test_unused_typevar_pep695_switch_order(self):
""",
)

@test_utils.skipBeforePy((3, 12), "PEP 695 - 3.12 feature")
def test_unused_typevar_pep695_function_type_var_single(self):
ty = self.Infer("""
def foo[T, S](a: T) -> T:
return a
""")
self.assertTypesMatchPytd(
ty,
"""
from typing import TypeVar
T = TypeVar("T")

def foo(a: T) -> T: ...
""",
)

@test_utils.skipBeforePy((3, 12), "PEP 695 - 3.12 feature")
def test_unused_typevar_pep695_function_type_var_double(self):
ty = self.Infer("""
def foo[T, S](a: T, b: S) -> tuple[S, T]:
return (a, b)
""")
self.assertTypesMatchPytd(
ty,
"""
from typing import TypeVar
S = TypeVar('S')
T = TypeVar('T')

def foo(a: T, b: S) -> tuple[S, T]: ...
""",
)

def test_import_typevar(self):
with test_utils.Tempdir() as d:
d.create_file("a.pyi", """T = TypeVar("T")""")
Expand Down
8 changes: 7 additions & 1 deletion pytype/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3939,7 +3939,13 @@ def byte_INTRINSIC_TYPEVAR_WITH_CONSTRAINTS(self, state):
return state

def byte_INTRINSIC_SET_FUNCTION_TYPE_PARAMS(self, state):
# TODO: b/350910471 - Implement to support PEP 695
# Second parameter here is a type parameter, it's stored to the
# __type_params__ function attribute at runtime, but this information is not
# consumed by us. This intrinsic consumes two parameters which is the
# function object and the type parameter list and returns the function
# object.
state, (func, _) = state.popn(2)
state = state.push(func)
return state


Expand Down
Loading