.. class:: NamedExpr(target, value)
- A named expression. This AST node is produced by the assignment expressions
- operator (also known as the walrus operator). As opposed to the :class:`Assign`
- node in which the first argument can be multiple nodes, in this case both
- ``target`` and ``value`` must be single nodes.
+ A named expression. This AST node is produced by the assignment expressions
+ operator (also known as the walrus operator). As opposed to the :class:`Assign`
+ node in which the first argument can be multiple nodes, in this case both
+ ``target`` and ``value`` must be single nodes.
.. doctest::
target=Name(id='x', ctx=Store()),
value=Constant(value=4)))
+ .. versionadded:: 3.8
Subscripting
~~~~~~~~~~~~
value=Name(id='int', ctx=Load()))],
type_ignores=[])
+ .. versionadded:: 3.12
Other statements which are only applicable inside functions or loops are
described in other sections.
finalbody=[])],
type_ignores=[])
+ .. versionadded:: 3.11
.. class:: ExceptHandler(type, name, body)
that is being matched against the cases) and ``cases`` contains an iterable of
:class:`match_case` nodes with the different cases.
+ .. versionadded:: 3.10
+
.. class:: match_case(pattern, guard, body)
A single case pattern in a ``match`` statement. ``pattern`` contains the
value=Constant(value=Ellipsis))])])],
type_ignores=[])
+ .. versionadded:: 3.10
+
.. class:: MatchValue(value)
A match literal or value pattern that compares by equality. ``value`` is
value=Constant(value=Ellipsis))])])],
type_ignores=[])
+ .. versionadded:: 3.10
+
.. class:: MatchSingleton(value)
A match literal pattern that compares by identity. ``value`` is the
value=Constant(value=Ellipsis))])])],
type_ignores=[])
+ .. versionadded:: 3.10
+
.. class:: MatchSequence(patterns)
A match sequence pattern. ``patterns`` contains the patterns to be matched
value=Constant(value=Ellipsis))])])],
type_ignores=[])
+ .. versionadded:: 3.10
+
.. class:: MatchStar(name)
Matches the rest of the sequence in a variable length match sequence pattern.
value=Constant(value=Ellipsis))])])],
type_ignores=[])
+ .. versionadded:: 3.10
+
.. class:: MatchMapping(keys, patterns, rest)
A match mapping pattern. ``keys`` is a sequence of expression nodes.
value=Constant(value=Ellipsis))])])],
type_ignores=[])
+ .. versionadded:: 3.10
+
.. class:: MatchClass(cls, patterns, kwd_attrs, kwd_patterns)
A match class pattern. ``cls`` is an expression giving the nominal class to
value=Constant(value=Ellipsis))])])],
type_ignores=[])
+ .. versionadded:: 3.10
+
.. class:: MatchAs(pattern, name)
A match "as-pattern", capture pattern or wildcard pattern. ``pattern``
value=Constant(value=Ellipsis))])])],
type_ignores=[])
+ .. versionadded:: 3.10
+
.. class:: MatchOr(patterns)
A match "or-pattern". An or-pattern matches each of its subpatterns in turn
value=Constant(value=Ellipsis))])])],
type_ignores=[])
+ .. versionadded:: 3.10
+
.. _ast-type-params:
Type parameters
ctx=Load()))],
type_ignores=[])
+ .. versionadded:: 3.12
+
.. class:: ParamSpec(name)
A :class:`typing.ParamSpec`. ``name`` is the name of the parameter specification.
ctx=Load()))],
type_ignores=[])
+ .. versionadded:: 3.12
+
.. class:: TypeVarTuple(name)
A :class:`typing.TypeVarTuple`. ``name`` is the name of the type variable tuple.
ctx=Load()))],
type_ignores=[])
+ .. versionadded:: 3.12
+
Function and class definitions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``type_comment`` is an optional string with the type annotation as a comment.
+ .. versionchanged:: 3.12
+ Added ``type_params``.
+
.. class:: Lambda(args, body)
type_params=[])],
type_ignores=[])
+ .. versionchanged:: 3.12
+ Added ``type_params``.
+
Async and await
^^^^^^^^^^^^^^^
An ``async def`` function definition. Has the same fields as
:class:`FunctionDef`.
+ .. versionchanged:: 3.12
+ Added ``type_params``.
+
.. class:: Await(value)