Skip to content

Support for PEP 695 #15238

Closed
Closed
@erictraut

Description

@erictraut

PEP 695 was accepted, and it looks like it will make it into Python 3.12. This PEP adds support for a new type parameter syntax for generic classes and methods. It also adds a new syntax for type aliases (both generic and not).

PEP 695 functionality is implemented in pyright today. It would be great to see it also implemented in mypy and the other major type checkers so we could start to use the new features in type stubs.

Here is a rough task list associated with this work:

  • Add support for infer_variance keyword parameter in TypeVar; see this section of PEP for details
  • Add support for variance inference (similar to variance enforcement in Protocol classes today); see this section of PEP for details
  • Add support for new AST nodes for type statement; see this section of PEP for details
  • Add support for new AST nodes for generic classes and functions; see this section of PEP for details
  • Add support for evaluating type parameters using the new syntax (including TypeVar bounds and constraints, TypeVarTuple and ParamSpec); see this section of PEP for details
  • Add support for defining type aliases using the new type statement (including generic and recursive type definitions); see this section of PEP for details
  • Add support for defining generic classes and functions with explicit type parameter lists using new syntax
  • Add support for functional form of TypeAliasType, supported for backward compatibility; see this section of PEP for details
  • Add detection and error reporting for use of traditional TypeVar, TypeVarTuple, or ParamSpec in conjunction with new syntax; see this section of PEP for details
  • Add detection and error reporting for use of assignment expressions, yield, yield from, and await expressions within the type parameter scope; see this section of PEP for details

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions