cpython/Misc/NEWS.d/next/Core and Builtins/2023-04-25-08-43-11.gh-issue-103763.ZLBZk1.rst
Jelle Zijlstra 24d8b88420
gh-103763: Implement PEP 695 (#103764)
This implements PEP 695, Type Parameter Syntax. It adds support for:

- Generic functions (def func[T](): ...)
- Generic classes (class X[T](): ...)
- Type aliases (type X = ...)
- New scoping when the new syntax is used within a class body
- Compiler and interpreter changes to support the new syntax and scoping rules 

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: Eric Traut <eric@traut.com>
Co-authored-by: Larry Hastings <larry@hastings.org>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-15 20:36:23 -07:00

23 lines
1.1 KiB
ReStructuredText

Implement :pep:`695`, adding syntactic support for generic classes, generic
functions, and type aliases.
A new ``type X = ...`` syntax is added for type aliases, which resolves at
runtime to an instance of the new class ``typing.TypeAliasType``.
The value is lazily evaluated and is accessible through the ``.__value__``
attribute. This is implemented as a new AST node ``ast.TypeAlias``.
New syntax (``class X[T]: ...``, ``def func[T](): ...``) is added for defining
generic functions and classes. This is implemented as a new
``typeparams`` attribute on the AST nodes for classes and functions.
This node holds instances of the new AST classes ``ast.TypeVar``,
``ast.ParamSpec``, and ``ast.TypeVarTuple``.
``typing.TypeVar``, ``typing.ParamSpec``, ``typing.ParamSpecArgs``,
``typing.ParamSpecKwargs``, ``typing.TypeVarTuple``, and
``typing.Generic`` are now implemented in C rather than Python.
There are new bytecode instructions ``LOAD_LOCALS``,
``LOAD_CLASSDICT_OR_GLOBAL``, and ``LOAD_CLASSDICT_OR_DEREF``
to support correct resolution of names in class namespaces.
Patch by Eric Traut, Larry Hastings, and Jelle Zijlstra.