Skip to content

Commit 628c88d

Browse files
Update ast for 3.12 (#10201)
1 parent 7bc4be0 commit 628c88d

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

stdlib/_ast.pyi

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import sys
2+
import typing_extensions
23
from typing import Any, ClassVar
3-
from typing_extensions import Literal, TypeAlias
4+
from typing_extensions import Literal
45

56
PyCF_ONLY_AST: Literal[1024]
67
if sys.version_info >= (3, 8):
78
PyCF_TYPE_COMMENTS: Literal[4096]
89
PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192]
910

10-
_Identifier: TypeAlias = str
11+
_Identifier: typing_extensions.TypeAlias = str
1112

1213
class AST:
1314
if sys.version_info >= (3, 10):
@@ -59,31 +60,43 @@ class Expression(mod):
5960
class stmt(AST): ...
6061

6162
class FunctionDef(stmt):
62-
if sys.version_info >= (3, 10):
63+
if sys.version_info >= (3, 12):
64+
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment", "type_params")
65+
elif sys.version_info >= (3, 10):
6366
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment")
6467
name: _Identifier
6568
args: arguments
6669
body: list[stmt]
6770
decorator_list: list[expr]
6871
returns: expr | None
72+
if sys.version_info >= (3, 12):
73+
type_params: list[type_param]
6974

7075
class AsyncFunctionDef(stmt):
71-
if sys.version_info >= (3, 10):
76+
if sys.version_info >= (3, 12):
77+
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment", "type_params")
78+
elif sys.version_info >= (3, 10):
7279
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment")
7380
name: _Identifier
7481
args: arguments
7582
body: list[stmt]
7683
decorator_list: list[expr]
7784
returns: expr | None
85+
if sys.version_info >= (3, 12):
86+
type_params: list[type_param]
7887

7988
class ClassDef(stmt):
80-
if sys.version_info >= (3, 10):
89+
if sys.version_info >= (3, 12):
90+
__match_args__ = ("name", "bases", "keywords", "body", "decorator_list", "type_params")
91+
elif sys.version_info >= (3, 10):
8192
__match_args__ = ("name", "bases", "keywords", "body", "decorator_list")
8293
name: _Identifier
8394
bases: list[expr]
8495
keywords: list[keyword]
8596
body: list[stmt]
8697
decorator_list: list[expr]
98+
if sys.version_info >= (3, 12):
99+
type_params: list[type_param]
87100

88101
class Return(stmt):
89102
if sys.version_info >= (3, 10):
@@ -366,10 +379,10 @@ class Attribute(expr):
366379
ctx: expr_context
367380

368381
if sys.version_info >= (3, 9):
369-
_Slice: TypeAlias = expr
382+
_Slice: typing_extensions.TypeAlias = expr
370383
else:
371384
class slice(AST): ...
372-
_Slice: TypeAlias = slice
385+
_Slice: typing_extensions.TypeAlias = slice
373386

374387
class Slice(_Slice):
375388
if sys.version_info >= (3, 10):
@@ -526,7 +539,7 @@ if sys.version_info >= (3, 10):
526539

527540
class pattern(AST): ...
528541
# Without the alias, Pyright complains variables named pattern are recursively defined
529-
_Pattern: TypeAlias = pattern
542+
_Pattern: typing_extensions.TypeAlias = pattern
530543

531544
class match_case(AST):
532545
__match_args__ = ("pattern", "guard", "body")
@@ -571,3 +584,25 @@ if sys.version_info >= (3, 10):
571584
class MatchOr(pattern):
572585
__match_args__ = ("patterns",)
573586
patterns: list[pattern]
587+
588+
if sys.version_info >= (3, 12):
589+
class type_param(AST): ...
590+
591+
class TypeVar(type_param):
592+
__match_args__ = ("name", "bound")
593+
name: _Identifier
594+
bound: expr | None
595+
596+
class ParamSpec(type_param):
597+
__match_args__ = ("name",)
598+
name: _Identifier
599+
600+
class TypeVarTuple(type_param):
601+
__match_args__ = ("name",)
602+
name: _Identifier
603+
604+
class TypeAlias(stmt):
605+
__match_args__ = ("name", "typeparams", "value")
606+
name: Name
607+
type_params: list[type_param]
608+
value: expr

stdlib/ast.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sys
33
from _ast import *
44
from _typeshed import ReadableBuffer, Unused
55
from collections.abc import Iterator
6-
from typing import Any, TypeVar, overload
6+
from typing import Any, TypeVar as _TypeVar, overload
77
from typing_extensions import Literal
88

99
if sys.version_info >= (3, 8):
@@ -168,7 +168,7 @@ class NodeTransformer(NodeVisitor):
168168
# The usual return type is AST | None, but Iterable[AST]
169169
# is also allowed in some cases -- this needs to be mapped.
170170

171-
_T = TypeVar("_T", bound=AST)
171+
_T = _TypeVar("_T", bound=AST)
172172

173173
if sys.version_info >= (3, 8):
174174
@overload

0 commit comments

Comments
 (0)