Skip to content

Add support for PEP 695 #5062

@charliermarsh

Description

@charliermarsh

Summary

PEP 695 adds new syntax for type parameters and generics. A few examples:

class ClassA[T: str]:
    def method1(self) -> T:
        ...

type ListOrSet[T] = list[T] | set[T]

There are a few pieces of work involved in this:

  • Adding these elements to the AST.
  • Adding these elements to the parser (especially the type soft keyword).
  • Adding these elements to the visitor, and to any rules that do custom visiting.
  • Adding these elements to our semantic model (need to look into how scoping and resolution works).

This will be Ruff's first time undergoing a significant grammar and syntax change (apart from adding structural pattern matching), so it's a great opportunity to set the project's standards for keeping up with Python's evolution.

Specifically, the final Python 3.12 release is expected on 2023-10-02. We should aim to support PEP 695 by that date at the latest.

Metadata

Metadata

Assignees

Labels

coreRelated to core functionalitypython312Related to Python 3.12

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions