8000 [mypyc] Support new syntax for generic functions and classes (PEP 695) by JukkaL · Pull Request #17357 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

[mypyc] Support new syntax for generic functions and classes (PEP 695) #17357

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

Merged
merged 16 commits into from
Jun 11, 2024
Merged
Next Next commit
WIP start adding tests
  • Loading branch information
JukkaL committed Jun 10, 2024
commit 16c00b12fd283fad59ae5634be8a1314540df319
3 changes: 3 additions & 0 deletions mypyc/test-data/fixtures/typing-full.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,6 @@ class _TypedDict(Mapping[str, object]):
def pop(self, k: NoReturn, default: T = ...) -> object: ...
def update(self: T, __m: T) -> None: ...
def __delitem__(self, k: NoReturn) -> None: ...

class TypeAliasType:
pass
39 changes: 39 additions & 0 deletions mypyc/test-data/run-python312.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[case testPEP695Basics]
# flags: --enable-incomplete-feature=NewGenericSyntax
from typing import Any, TypeAliasType

def id[T](x: T) -> T:
return x

def test_call_generic_function() -> None:
assert id(2) == 2
assert id('x') == 'x'

class C[T]:
x: T

def __init__(self, x: T) -> None:
self.x = x

def test_generic_class() -> None:
c = C(5)
assert c.x == 5
c2 = C[str]('x')
assert c2.x == 'x'

def x_test_generic_class_via_any() -> None:
c_any: Any = C
c3 = c_any(2)
assert c3.x == 2
c4 = c_any[str]('y')
assert c4.x == 'y'

class D: pass

#type A = D

#def test_simple_type_alias() -> None:
# assert isinstance(A, TypeAliasType)
# assert str(A) == "A"

[typing fixtures/typing-full.pyi]
3 changes: 3 additions & 0 deletions mypyc/test/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@

if sys.version_info >= (3, 10):
files.append("run-match.test")
if sys.version_info >= (3, 12):
files.append("run-python312.test")

setup_format = """\
from setuptools import setup
Expand Down Expand Up @@ -194,6 +196,7 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) ->
options.preserve_asts = True
options.allow_empty_bodies = True
options.incremental = self.separate
options.enable_incomplete_feature.append("NewGenericSyntax")

# Avoid checking modules/packages named 'unchecked', to provide a way
# to test interacting with code we don't have types for.
Expand Down
0