RustPython / Parser

MIT License
66 stars 24 forks source link

Add parsing of type alias statements i.e. the `type` keyword #97

Closed zanieb closed 11 months ago

zanieb commented 11 months ago

Extends #95 Closes #82

Adds parsing of new type soft keyword for defining type aliases.

Supports type alias statements as defined in PEP 695 e.g.

# A non-generic type alias
type IntOrStr = int | str

# A generic type alias
type ListOrSet[T] = list[T] | set[T]

# A type alias that includes a forward reference
type AnimalOrVegetable = Animal | "Vegetable"

# A generic self-referential type alias
type RecursiveList[T] = T | list[RecursiveList[T]]

All type parameter kinds are supported as in #95.

Builds on soft keyword abstractions introduced in https://github.com/RustPython/RustPython/pull/4519

charliermarsh commented 11 months ago

Nice job figuring this out. A couple questions to confirm my understanding of the soft-keyword heuristics.