Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
786a436
First docs work
JelleZijlstra May 13, 2023
c1f266e
More words
JelleZijlstra May 15, 2023
040c4fd
Merge remote-tracking branch 'upstream/main' into pep695docs
JelleZijlstra May 19, 2023
e3dfb27
ast changes, fix build
JelleZijlstra May 19, 2023
f5b1d86
the big PEP list
JelleZijlstra May 19, 2023
5798631
dis
JelleZijlstra May 19, 2023
0f76679
default roles
JelleZijlstra May 19, 2023
cb76021
TODOs in compound_stmts
JelleZijlstra May 19, 2023
12c1249
minor
JelleZijlstra May 19, 2023
94a4da2
Remove broken link
JelleZijlstra May 19, 2023
815a021
update dis.dis docs
JelleZijlstra May 19, 2023
17ac785
TypeAlias is deprecated
JelleZijlstra May 19, 2023
1311399
Type aliases should now use the type statement
JelleZijlstra May 19, 2023
123752c
syntax
JelleZijlstra May 19, 2023
9d6e0c0
Merge branch 'main' into pep695docs
JelleZijlstra May 19, 2023
e955a45
Expand typing.rst
JelleZijlstra May 20, 2023
d7f2b55
Finish the type statement
JelleZijlstra May 20, 2023
53c4916
What's New
JelleZijlstra May 20, 2023
edec8c3
Merge remote-tracking branch 'upstream/main' into pep695docs
JelleZijlstra May 20, 2023
bc1c1d2
typo
JelleZijlstra May 20, 2023
b1a843c
FQNs in ast.rst
JelleZijlstra May 20, 2023
e690aff
Merge remote-tracking branch 'upstream/main' into pep695docs
JelleZijlstra May 21, 2023
cc5b51c
Document TypeVar constructor signature, discuss variance
JelleZijlstra May 21, 2023
b0e1ce3
TypeVarTuple signature
JelleZijlstra May 21, 2023
382ff2c
Fix sig
JelleZijlstra May 21, 2023
db94e4f
Document TypeVar attributes, fix indentation
JelleZijlstra May 21, 2023
18b9d63
Fix TypeVarTuple indentation
JelleZijlstra May 21, 2023
b7ba811
Merge branch 'main' into pep695docs
AlexWaygood May 22, 2023
fd1d0a8
s/typeparams/type_params/
JelleZijlstra May 22, 2023
62ba887
Apply suggestions from code review
JelleZijlstra May 22, 2023
200eba1
Reword long dis sentence
JelleZijlstra May 22, 2023
adaf874
Manual changes from Alex review
JelleZijlstra May 22, 2023
4481d6d
Merge remote-tracking branch 'upstream/main' into pep695docs
JelleZijlstra May 22, 2023
365ae7b
Improve ast.TypeAlias text
JelleZijlstra May 22, 2023
96e5d16
Document __type_params__
JelleZijlstra May 22, 2023
0204d54
Add to datamodel.rst
JelleZijlstra May 22, 2023
f426d39
Wording change
JelleZijlstra May 22, 2023
60d7783
Update Doc/library/typing.rst
JelleZijlstra May 22, 2023
63d4d84
Apply suggestions from code review
JelleZijlstra May 22, 2023
fd6751a
fix indentation
JelleZijlstra May 22, 2023
499dae1
Link to generic functions
JelleZijlstra May 22, 2023
b4172c9
Move up variance paragraph
JelleZijlstra May 22, 2023
e9bc4a8
Merge remote-tracking branch 'upstream/main' into pep695docs
JelleZijlstra May 23, 2023
0d37675
Some Alex comments
JelleZijlstra May 23, 2023
c94ee7c
Fix alignment
JelleZijlstra May 23, 2023
1630342
doctest maybe
JelleZijlstra May 23, 2023
aade45a
More Alex suggestions
JelleZijlstra May 23, 2023
57b9992
Feedback from Carl
JelleZijlstra May 23, 2023
7953d2c
Section on lazy eval
JelleZijlstra May 23, 2023
9128c72
More cross-refs
JelleZijlstra May 23, 2023
0511b6a
Can't have nice things
JelleZijlstra May 23, 2023
4fd3f02
Respond to some feedback
JelleZijlstra May 24, 2023
fff0df4
Undo unnecessary typing.rst changes
JelleZijlstra May 24, 2023
ba2a103
Merge remote-tracking branch 'upstream/main' into pep695docs
JelleZijlstra May 24, 2023
1c6807d
more words
JelleZijlstra May 24, 2023
6386475
or
JelleZijlstra May 24, 2023
cd4206c
Update Doc/reference/compound_stmts.rst
JelleZijlstra May 24, 2023
e307177
Merge branch 'main' into pep695docs
AlexWaygood May 25, 2023
d7e1c6c
Apply suggestions from code review
JelleZijlstra May 26, 2023
f878970
More feedback from Alex
JelleZijlstra May 26, 2023
a4bd32a
fixes
JelleZijlstra May 26, 2023
ee8f952
Merge remote-tracking branch 'upstream/main' into pep695docs
JelleZijlstra May 26, 2023
7a709d7
Rewrite and extend some docstrings
JelleZijlstra May 26, 2023
0cfeb92
More comments
JelleZijlstra May 26, 2023
f978766
Docstring fixes
JelleZijlstra May 26, 2023
bba092d
tables
JelleZijlstra May 26, 2023
57ddbef
more fixes
JelleZijlstra May 26, 2023
67acd98
Merge remote-tracking branch 'upstream/main' into pep695docs
JelleZijlstra May 26, 2023
988fc7c
Merge branch 'main' into pep695docs
AlexWaygood May 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ast changes, fix build
  • Loading branch information
JelleZijlstra committed May 19, 2023
commit e3dfb2750f9317b224d2fc74b07a18a778f64be4
102 changes: 100 additions & 2 deletions Doc/library/ast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,25 @@ Statements
type_ignores=[])


.. class:: TypeAlias(name, typeparams, value)

A type alias created through the :keyword:`type` statement. ``name``
is the name of the alias, ``typeparams`` is a list of
:ref:`type parameters <ast-type-params>`, and ``value`` is the value of the
type alias.
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated

.. doctest::

>>> print(ast.dump(ast.parse('type Alias = int'), indent=4))
Module(
body=[
TypeAlias(
name=Name(id='Alias', ctx=Store()),
typeparams=[],
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated
value=Name(id='int', ctx=Load()))],
type_ignores=[])


Other statements which are only applicable inside functions or loops are
described in other sections.

Expand Down Expand Up @@ -1644,15 +1663,93 @@ Pattern matching
value=Constant(value=Ellipsis))])])],
type_ignores=[])

.. _ast-type-params:

Type parameters
^^^^^^^^^^^^^^^

:ref:`Type parameters <type-params>` can exist on classes, functions, and type
aliases.

.. class:: TypeVar(name, bound)

A :class:`~typing.TypeVar`. ``name`` is the name of the type variable, and
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated
``bound`` is the bound or constraints, if any. If the value is a :class:`Tuple`,
it represents constraints; otherwise it represents the bound.

.. doctest::

>>> print(ast.dump(ast.parse("type Alias[T: int] = list[T]"), indent=4))
Module(
body=[
TypeAlias(
name=Name(id='Alias', ctx=Store()),
typeparams=[
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated
TypeVar(
name='T',
bound=Name(id='int', ctx=Load()))],
value=Subscript(
value=Name(id='list', ctx=Load()),
slice=Name(id='T', ctx=Load()),
ctx=Load()))],
type_ignores=[])

.. class:: ParamSpec(name)

A :class:`~typing.ParamSpec`. ``name`` is the name of the parameter specification.

.. doctest::

>>> print(ast.dump(ast.parse("type Alias[**P] = Callable[P, int]"), indent=4))
Module(
body=[
TypeAlias(
name=Name(id='Alias', ctx=Store()),
typeparams=[
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated
ParamSpec(name='P')],
value=Subscript(
value=Name(id='Callable', ctx=Load()),
slice=Tuple(
elts=[
Name(id='P', ctx=Load()),
Name(id='int', ctx=Load())],
ctx=Load()),
ctx=Load()))],
type_ignores=[])

.. class:: TypeVarTuple(name)

A :class:`~typing.TypeVarTuple`. ``name`` is the name of the type variable tuple.

.. doctest::

>>> print(ast.dump(ast.parse("type Alias[*Ts] = tuple[*Ts]"), indent=4))
Module(
body=[
TypeAlias(
name=Name(id='Alias', ctx=Store()),
typeparams=[
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated
TypeVarTuple(name='Ts')],
value=Subscript(
value=Name(id='tuple', ctx=Load()),
slice=Tuple(
elts=[
Starred(
value=Name(id='Ts', ctx=Load()),
ctx=Load())],
ctx=Load()),
ctx=Load()))],
type_ignores=[])

Function and class definitions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. class:: FunctionDef(name, args, body, decorator_list, returns, type_comment)
.. class:: FunctionDef(name, typeparams, args, body, decorator_list, returns, type_comment)
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated

A function definition.

* ``name`` is a raw string of the function name.
* ``typeparams`` is a list of :ref:`type parameters <ast-type-params>`.
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated
* ``args`` is an :class:`arguments` node.
* ``body`` is the list of nodes inside the function.
* ``decorator_list`` is the list of decorators to be applied, stored outermost
Expand Down Expand Up @@ -1820,11 +1917,12 @@ Function and class definitions
type_ignores=[])


.. class:: ClassDef(name, bases, keywords, starargs, kwargs, body, decorator_list)
.. class:: ClassDef(name, typeparams, bases, keywords, starargs, kwargs, body, decorator_list)
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated

A class definition.

* ``name`` is a raw string for the class name
* ``typeparams`` is a list of :ref:`type parameters <ast-type-params>`.
Comment thread
JelleZijlstra marked this conversation as resolved.
Outdated
* ``bases`` is a list of nodes for explicitly specified base classes.
* ``keywords`` is a list of :class:`keyword` nodes, principally for 'metaclass'.
Other keywords will be passed to the metaclass, as per `PEP-3115
Expand Down
8 changes: 3 additions & 5 deletions Doc/reference/compound_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ For :data:`!typing.TypeVar`\ s declared using the type parameter list syntax,
the bound and constraints are not evaluated when the generic object is created,
but only when the value is explicitly accessed through the attributes ``__bound__``
and ``__constraints__``. To accomplish this, the bounds or constraints are
evaluated in a separate :ref:`type scope <type-scopes>`.
evaluated in a separate :ref:`annotation scope <annotation-scopes>`.

:data:`typing.TypeVarTuple`\ s and :data:`typing.ParamSpec`\ s cannot have bounds
or constraints.
Expand Down Expand Up @@ -1792,11 +1792,11 @@ This is equivalent to::
Generic type aliases
--------------------

The :keyword:`type` statement can also be used to create a generic type alias:
The :keyword:`type` statement can also be used to create a generic type alias::

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

Except for the lazy evaluation of the value, this is equivalent to:
Except for the lazy evaluation of the value, this is equivalent to::

def' TYPE_PARAMS_OF_ListOrSet():
T = typing.TypeVar("T")
Expand All @@ -1807,8 +1807,6 @@ Except for the lazy evaluation of the value, this is equivalent to:
return typing.TypeAliasType("ListOrSet", VALUE_OF_ListOrSet(), type_params=(T,))
ListOrSet = TYPE_PARAMS_OF_ListOrSet()



.. rubric:: Footnotes

.. [#] The exception is propagated to the invocation stack unless
Expand Down
2 changes: 1 addition & 1 deletion Doc/reference/executionmodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ However, the following will succeed::
Annotation scopes
-----------------

:ref:`Type parameter lists <type-params>`` and :keyword:`type` statements
:ref:`Type parameter lists <type-params>` and :keyword:`type` statements
introduce *annotation scopes*, which behave mostly like function scopes,
but with some exceptions discussed below. :term:`Annotations <annotation>`
currently do not use annotation scopes, but they are expected to use
Expand Down