RustPython / Parser

MIT License
77 stars 29 forks source link

PEP 695 – Type Parameter Syntax #82

Closed tjf801 closed 1 year ago

tjf801 commented 1 year ago

Feature

Seeing as how Python 3.12 is now in beta, I feel like RustPython should also work on being able to parse the new syntax introduced in PEP 695, which makes it much easier to type-hint generic functions and types in the language. I ran into this while trying to start writing a custom type checker, and wanted to use rustpython_ast to parse Python 3.12 code that uses this new syntax. Some examples include:

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

type Point = tuple[float, float]

type MappingOrSequence[T] = Mapping[int, T] | Sequence[T]

class Container[T](Sequence[T]): ...

Python Documentation or reference to CPython source code

zanieb commented 1 year ago

I'll be working on this for use in Ruff — I expect my changes will land in a pull request here.