Update ast for 3.12 (#10201)

This commit is contained in:
Jelle Zijlstra
2023-06-02 17:11:13 -07:00
committed by GitHub
parent 7bc4be08d8
commit 628c88d995
2 changed files with 45 additions and 10 deletions

View File

@@ -1,13 +1,14 @@
import sys
import typing_extensions
from typing import Any, ClassVar
from typing_extensions import Literal, TypeAlias
from typing_extensions import Literal
PyCF_ONLY_AST: Literal[1024]
if sys.version_info >= (3, 8):
PyCF_TYPE_COMMENTS: Literal[4096]
PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192]
_Identifier: TypeAlias = str
_Identifier: typing_extensions.TypeAlias = str
class AST:
if sys.version_info >= (3, 10):
@@ -59,31 +60,43 @@ class Expression(mod):
class stmt(AST): ...
class FunctionDef(stmt):
if sys.version_info >= (3, 10):
if sys.version_info >= (3, 12):
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment", "type_params")
elif sys.version_info >= (3, 10):
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment")
name: _Identifier
args: arguments
body: list[stmt]
decorator_list: list[expr]
returns: expr | None
if sys.version_info >= (3, 12):
type_params: list[type_param]
class AsyncFunctionDef(stmt):
if sys.version_info >= (3, 10):
if sys.version_info >= (3, 12):
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment", "type_params")
elif sys.version_info >= (3, 10):
__match_args__ = ("name", "args", "body", "decorator_list", "returns", "type_comment")
name: _Identifier
args: arguments
body: list[stmt]
decorator_list: list[expr]
returns: expr | None
if sys.version_info >= (3, 12):
type_params: list[type_param]
class ClassDef(stmt):
if sys.version_info >= (3, 10):
if sys.version_info >= (3, 12):
__match_args__ = ("name", "bases", "keywords", "body", "decorator_list", "type_params")
elif sys.version_info >= (3, 10):
__match_args__ = ("name", "bases", "keywords", "body", "decorator_list")
name: _Identifier
bases: list[expr]
keywords: list[keyword]
body: list[stmt]
decorator_list: list[expr]
if sys.version_info >= (3, 12):
type_params: list[type_param]
class Return(stmt):
if sys.version_info >= (3, 10):
@@ -366,10 +379,10 @@ class Attribute(expr):
ctx: expr_context
if sys.version_info >= (3, 9):
_Slice: TypeAlias = expr
_Slice: typing_extensions.TypeAlias = expr
else:
class slice(AST): ...
_Slice: TypeAlias = slice
_Slice: typing_extensions.TypeAlias = slice
class Slice(_Slice):
if sys.version_info >= (3, 10):
@@ -526,7 +539,7 @@ if sys.version_info >= (3, 10):
class pattern(AST): ...
# Without the alias, Pyright complains variables named pattern are recursively defined
_Pattern: TypeAlias = pattern
_Pattern: typing_extensions.TypeAlias = pattern
class match_case(AST):
__match_args__ = ("pattern", "guard", "body")
@@ -571,3 +584,25 @@ if sys.version_info >= (3, 10):
class MatchOr(pattern):
__match_args__ = ("patterns",)
patterns: list[pattern]
if sys.version_info >= (3, 12):
class type_param(AST): ...
class TypeVar(type_param):
__match_args__ = ("name", "bound")
name: _Identifier
bound: expr | None
class ParamSpec(type_param):
__match_args__ = ("name",)
name: _Identifier
class TypeVarTuple(type_param):
__match_args__ = ("name",)
name: _Identifier
class TypeAlias(stmt):
__match_args__ = ("name", "typeparams", "value")
name: Name
type_params: list[type_param]
value: expr

View File

@@ -3,7 +3,7 @@ import sys
from _ast import *
from _typeshed import ReadableBuffer, Unused
from collections.abc import Iterator
from typing import Any, TypeVar, overload
from typing import Any, TypeVar as _TypeVar, overload
from typing_extensions import Literal
if sys.version_info >= (3, 8):
@@ -168,7 +168,7 @@ class NodeTransformer(NodeVisitor):
# The usual return type is AST | None, but Iterable[AST]
# is also allowed in some cases -- this needs to be mapped.
_T = TypeVar("_T", bound=AST)
_T = _TypeVar("_T", bound=AST)
if sys.version_info >= (3, 8):
@overload