@@ -481,7 +481,7 @@ Expressions
481481 Comparison operator tokens.
482482
483483
484- .. class :: Call(func, args, keywords, starargs, kwargs )
484+ .. class :: Call(func, args, keywords)
485485
486486 A function call. ``func `` is the function, which will often be a
487487 :class: `Name ` or :class: `Attribute ` object. Of the arguments:
@@ -491,7 +491,7 @@ Expressions
491491 arguments passed by keyword.
492492
493493 When creating a ``Call `` node, ``args `` and ``keywords `` are required, but
494- they can be empty lists. `` starargs `` and `` kwargs `` are optional.
494+ they can be empty lists.
495495
496496 .. doctest ::
497497
@@ -917,6 +917,25 @@ Statements
917917 type_ignores=[])
918918
919919
920+ .. class :: TypeAlias(name, type_params, value)
921+
922+ A :ref: `type alias <type-aliases >` created through the :keyword: `type `
923+ statement. ``name `` is the name of the alias, ``type_params `` is a list of
924+ :ref: `type parameters <ast-type-params >`, and ``value `` is the value of the
925+ type alias.
926+
927+ .. doctest ::
928+
929+ >>> print (ast.dump(ast.parse(' type Alias = int' ), indent = 4 ))
930+ Module(
931+ body=[
932+ TypeAlias(
933+ name=Name(id='Alias', ctx=Store()),
934+ type_params=[],
935+ value=Name(id='int', ctx=Load()))],
936+ type_ignores=[])
937+
938+
920939Other statements which are only applicable inside functions or loops are
921940described in other sections.
922941
@@ -1644,15 +1663,93 @@ Pattern matching
16441663 value=Constant(value=Ellipsis))])])],
16451664 type_ignores=[])
16461665
1666+ .. _ast-type-params :
1667+
1668+ Type parameters
1669+ ^^^^^^^^^^^^^^^
1670+
1671+ :ref: `Type parameters <type-params >` can exist on classes, functions, and type
1672+ aliases.
1673+
1674+ .. class :: TypeVar(name, bound)
1675+
1676+ A :class: `typing.TypeVar `. ``name `` is the name of the type variable.
1677+ ``bound `` is the bound or constraints, if any. If ``bound `` is a :class: `Tuple `,
1678+ it represents constraints; otherwise it represents the bound.
1679+
1680+ .. doctest ::
1681+
1682+ >>> print (ast.dump(ast.parse(" type Alias[T: int] = list[T]" ), indent = 4 ))
1683+ Module(
1684+ body=[
1685+ TypeAlias(
1686+ name=Name(id='Alias', ctx=Store()),
1687+ type_params=[
1688+ TypeVar(
1689+ name='T',
1690+ bound=Name(id='int', ctx=Load()))],
1691+ value=Subscript(
1692+ value=Name(id='list', ctx=Load()),
1693+ slice=Name(id='T', ctx=Load()),
1694+ ctx=Load()))],
1695+ type_ignores=[])
1696+
1697+ .. class :: ParamSpec(name)
1698+
1699+ A :class: `typing.ParamSpec `. ``name `` is the name of the parameter specification.
1700+
1701+ .. doctest ::
1702+
1703+ >>> print (ast.dump(ast.parse(" type Alias[**P] = Callable[P, int]" ), indent = 4 ))
1704+ Module(
1705+ body=[
1706+ TypeAlias(
1707+ name=Name(id='Alias', ctx=Store()),
1708+ type_params=[
1709+ ParamSpec(name='P')],
1710+ value=Subscript(
1711+ value=Name(id='Callable', ctx=Load()),
1712+ slice=Tuple(
1713+ elts=[
1714+ Name(id='P', ctx=Load()),
1715+ Name(id='int', ctx=Load())],
1716+ ctx=Load()),
1717+ ctx=Load()))],
1718+ type_ignores=[])
1719+
1720+ .. class :: TypeVarTuple(name)
1721+
1722+ A :class: `typing.TypeVarTuple `. ``name `` is the name of the type variable tuple.
1723+
1724+ .. doctest ::
1725+
1726+ >>> print (ast.dump(ast.parse(" type Alias[*Ts] = tuple[*Ts]" ), indent = 4 ))
1727+ Module(
1728+ body=[
1729+ TypeAlias(
1730+ name=Name(id='Alias', ctx=Store()),
1731+ type_params=[
1732+ TypeVarTuple(name='Ts')],
1733+ value=Subscript(
1734+ value=Name(id='tuple', ctx=Load()),
1735+ slice=Tuple(
1736+ elts=[
1737+ Starred(
1738+ value=Name(id='Ts', ctx=Load()),
1739+ ctx=Load())],
1740+ ctx=Load()),
1741+ ctx=Load()))],
1742+ type_ignores=[])
16471743
16481744Function and class definitions
16491745^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16501746
1651- .. class :: FunctionDef(name, args, body, decorator_list, returns, type_comment)
1747+ .. class :: FunctionDef(name, type_params, args, body, decorator_list, returns, type_comment)
16521748
16531749 A function definition.
16541750
16551751 * ``name `` is a raw string of the function name.
1752+ * ``type_params `` is a list of :ref: `type parameters <ast-type-params >`.
16561753 * ``args `` is an :class: `arguments ` node.
16571754 * ``body `` is the list of nodes inside the function.
16581755 * ``decorator_list `` is the list of decorators to be applied, stored outermost
@@ -1820,18 +1917,16 @@ Function and class definitions
18201917 type_ignores=[])
18211918
18221919
1823- .. class :: ClassDef(name, bases, keywords, starargs, kwargs , body, decorator_list)
1920+ .. class :: ClassDef(name, type_params, bases, keywords , body, decorator_list)
18241921
18251922 A class definition.
18261923
18271924 * ``name `` is a raw string for the class name
1925+ * ``type_params `` is a list of :ref: `type parameters <ast-type-params >`.
18281926 * ``bases `` is a list of nodes for explicitly specified base classes.
18291927 * ``keywords `` is a list of :class: `keyword ` nodes, principally for 'metaclass'.
18301928 Other keywords will be passed to the metaclass, as per `PEP-3115
18311929 <https://peps.python.org/pep-3115/> `_.
1832- * ``starargs `` and ``kwargs `` are each a single node, as in a function call.
1833- starargs will be expanded to join the list of base classes, and kwargs will
1834- be passed to the metaclass.
18351930 * ``body `` is a list of nodes representing the code within the class
18361931 definition.
18371932 * ``decorator_list `` is a list of nodes, as in :class: `FunctionDef `.
0 commit comments