From d886a4511043fb531ee261d688dbaca9454f4ba4 Mon Sep 17 00:00:00 2001 From: bzoracler <50305397+bzoracler@users.noreply.github.com> Date: Thu, 9 May 2024 23:58:06 +1200 Subject: [PATCH] improvement: add precise AST subclass constructors --- stdlib/_ast.pyi | 369 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 367 insertions(+), 2 deletions(-) diff --git a/stdlib/_ast.pyi b/stdlib/_ast.pyi index 733e48dbf3ff..77b1db3de944 100644 --- a/stdlib/_ast.pyi +++ b/stdlib/_ast.pyi @@ -1,23 +1,37 @@ import sys import typing_extensions -from typing import Any, ClassVar, Literal +from typing import Any, ClassVar, Generic, Literal, TypedDict, overload PyCF_ONLY_AST: Literal[1024] PyCF_TYPE_COMMENTS: Literal[4096] PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192] +# Used for node end positions in constructor keyword arguments +_EndPositionT = typing_extensions.TypeVar("_EndPositionT", int, int | None, default=int | None) # noqa: Y023 + # Alias used for fields that must always be valid identifiers # A string `x` counts as a valid identifier if both the following are True # (1) `x.isidentifier()` evaluates to `True` # (2) `keyword.iskeyword(x)` evaluates to `False` _Identifier: typing_extensions.TypeAlias = str +# Corresponds to the names in the `_attributes` class variable which is non-empty in certain AST nodes +class _Attributes(TypedDict, Generic[_EndPositionT], total=False): + lineno: int + col_offset: int + end_lineno: _EndPositionT + end_col_offset: _EndPositionT + +if sys.version_info >= (3, 9): + _SliceAttributes: typing_extensions.TypeAlias = _Attributes +else: + class _SliceAttributes(TypedDict): ... + class AST: if sys.version_info >= (3, 10): __match_args__ = () _attributes: ClassVar[tuple[str, ...]] _fields: ClassVar[tuple[str, ...]] - def __init__(self, *args: Any, **kwargs: Any) -> None: ... class mod(AST): ... class type_ignore(AST): ... @@ -27,34 +41,40 @@ class TypeIgnore(type_ignore): __match_args__ = ("lineno", "tag") lineno: int tag: str + def __init__(self, lineno: int, tag: str) -> None: ... class FunctionType(mod): if sys.version_info >= (3, 10): __match_args__ = ("argtypes", "returns") argtypes: list[expr] returns: expr + def __init__(self, argtypes: list[expr], returns: expr) -> None: ... class Module(mod): if sys.version_info >= (3, 10): __match_args__ = ("body", "type_ignores") body: list[stmt] type_ignores: list[TypeIgnore] + def __init__(self, body: list[stmt], type_ignores: list[TypeIgnore]) -> None: ... class Interactive(mod): if sys.version_info >= (3, 10): __match_args__ = ("body",) body: list[stmt] + def __init__(self, body: list[stmt]) -> None: ... class Expression(mod): if sys.version_info >= (3, 10): __match_args__ = ("body",) body: expr + def __init__(self, body: expr) -> None: ... class stmt(AST): lineno: int col_offset: int end_lineno: int | None end_col_offset: int | None + def __init__(self, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class FunctionDef(stmt): if sys.version_info >= (3, 12): @@ -69,6 +89,42 @@ class FunctionDef(stmt): type_comment: str | None if sys.version_info >= (3, 12): type_params: list[type_param] + @overload + def __init__( + self, + name: _Identifier, + args: arguments, + body: list[stmt], + decorator_list: list[expr], + returns: expr | None, + type_comment: str | None, + type_params: list[type_param], + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... + @overload + def __init__( + self, + name: _Identifier, + args: arguments, + body: list[stmt], + decorator_list: list[expr], + returns: expr | None = None, + *, + type_comment: str | None = None, + type_params: list[type_param], + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... + else: + def __init__( + self, + name: _Identifier, + args: arguments, + body: list[stmt], + decorator_list: list[expr], + returns: expr | None = None, + type_comment: str | None = None, + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... class AsyncFunctionDef(stmt): if sys.version_info >= (3, 12): @@ -83,6 +139,42 @@ class AsyncFunctionDef(stmt): type_comment: str | None if sys.version_info >= (3, 12): type_params: list[type_param] + @overload + def __init__( + self, + name: _Identifier, + args: arguments, + body: list[stmt], + decorator_list: list[expr], + returns: expr | None, + type_comment: str | None, + type_params: list[type_param], + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... + @overload + def __init__( + self, + name: _Identifier, + args: arguments, + body: list[stmt], + decorator_list: list[expr], + returns: expr | None = None, + *, + type_comment: str | None = None, + type_params: list[type_param], + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... + else: + def __init__( + self, + name: _Identifier, + args: arguments, + body: list[stmt], + decorator_list: list[expr], + returns: expr | None = None, + type_comment: str | None = None, + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... class ClassDef(stmt): if sys.version_info >= (3, 12): @@ -96,16 +188,38 @@ class ClassDef(stmt): decorator_list: list[expr] if sys.version_info >= (3, 12): type_params: list[type_param] + def __init__( + self, + name: _Identifier, + bases: list[expr], + keywords: list[keyword], + body: list[stmt], + decorator_list: list[expr], + type_params: list[type_param], + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... + else: + def __init__( + self, + name: _Identifier, + bases: list[expr], + keywords: list[keyword], + body: list[stmt], + decorator_list: list[expr], + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... class Return(stmt): if sys.version_info >= (3, 10): __match_args__ = ("value",) value: expr | None + def __init__(self, value: expr | None = None, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Delete(stmt): if sys.version_info >= (3, 10): __match_args__ = ("targets",) targets: list[expr] + def __init__(self, targets: list[expr], **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Assign(stmt): if sys.version_info >= (3, 10): @@ -113,6 +227,9 @@ class Assign(stmt): targets: list[expr] value: expr type_comment: str | None + def __init__( + self, targets: list[expr], value: expr, type_comment: str | None = None, **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... class AugAssign(stmt): if sys.version_info >= (3, 10): @@ -120,6 +237,9 @@ class AugAssign(stmt): target: Name | Attribute | Subscript op: operator value: expr + def __init__( + self, target: Name | Attribute | Subscript, op: operator, value: expr, **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... class AnnAssign(stmt): if sys.version_info >= (3, 10): @@ -128,6 +248,25 @@ class AnnAssign(stmt): annotation: expr value: expr | None simple: int + @overload + def __init__( + self, + target: Name | Attribute | Subscript, + annotation: expr, + value: expr | None, + simple: int, + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... + @overload + def __init__( + self, + target: Name | Attribute | Subscript, + annotation: expr, + value: expr | None = None, + *, + simple: int, + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... class For(stmt): if sys.version_info >= (3, 10): @@ -137,6 +276,15 @@ class For(stmt): body: list[stmt] orelse: list[stmt] type_comment: str | None + def __init__( + self, + target: expr, + iter: expr, + body: list[stmt], + orelse: list[stmt], + type_comment: str | None = None, + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... class AsyncFor(stmt): if sys.version_info >= (3, 10): @@ -146,6 +294,15 @@ class AsyncFor(stmt): body: list[stmt] orelse: list[stmt] type_comment: str | None + def __init__( + self, + target: expr, + iter: expr, + body: list[stmt], + orelse: list[stmt], + type_comment: str | None = None, + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... class While(stmt): if sys.version_info >= (3, 10): @@ -153,6 +310,9 @@ class While(stmt): test: expr body: list[stmt] orelse: list[stmt] + def __init__( + self, test: expr, body: list[stmt], orelse: list[stmt], **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... class If(stmt): if sys.version_info >= (3, 10): @@ -160,6 +320,9 @@ class If(stmt): test: expr body: list[stmt] orelse: list[stmt] + def __init__( + self, test: expr, body: list[stmt], orelse: list[stmt], **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... class With(stmt): if sys.version_info >= (3, 10): @@ -167,6 +330,13 @@ class With(stmt): items: list[withitem] body: list[stmt] type_comment: str | None + def __init__( + self, + items: list[withitem], + body: list[stmt], + type_comment: str | None = None, + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... class AsyncWith(stmt): if sys.version_info >= (3, 10): @@ -174,12 +344,22 @@ class AsyncWith(stmt): items: list[withitem] body: list[stmt] type_comment: str | None + def __init__( + self, + items: list[withitem], + body: list[stmt], + type_comment: str | None = None, + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... class Raise(stmt): if sys.version_info >= (3, 10): __match_args__ = ("exc", "cause") exc: expr | None cause: expr | None + def __init__( + self, exc: expr | None = None, cause: expr | None = None, **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... class Try(stmt): if sys.version_info >= (3, 10): @@ -188,6 +368,14 @@ class Try(stmt): handlers: list[ExceptHandler] orelse: list[stmt] finalbody: list[stmt] + def __init__( + self, + body: list[stmt], + handlers: list[ExceptHandler], + orelse: list[stmt], + finalbody: list[stmt], + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... if sys.version_info >= (3, 11): class TryStar(stmt): @@ -196,17 +384,27 @@ if sys.version_info >= (3, 11): handlers: list[ExceptHandler] orelse: list[stmt] finalbody: list[stmt] + def __init__( + self, + body: list[stmt], + handlers: list[ExceptHandler], + orelse: list[stmt], + finalbody: list[stmt], + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... class Assert(stmt): if sys.version_info >= (3, 10): __match_args__ = ("test", "msg") test: expr msg: expr | None + def __init__(self, test: expr, msg: expr | None = None, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Import(stmt): if sys.version_info >= (3, 10): __match_args__ = ("names",) names: list[alias] + def __init__(self, names: list[alias], **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class ImportFrom(stmt): if sys.version_info >= (3, 10): @@ -214,21 +412,32 @@ class ImportFrom(stmt): module: str | None names: list[alias] level: int + @overload + def __init__( + self, module: str | None, names: list[alias], level: int, **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... + @overload + def __init__( + self, module: str | None = None, *, names: list[alias], level: int, **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... class Global(stmt): if sys.version_info >= (3, 10): __match_args__ = ("names",) names: list[_Identifier] + def __init__(self, names: list[_Identifier], **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Nonlocal(stmt): if sys.version_info >= (3, 10): __match_args__ = ("names",) names: list[_Identifier] + def __init__(self, names: list[_Identifier], **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Expr(stmt): if sys.version_info >= (3, 10): __match_args__ = ("value",) value: expr + def __init__(self, value: expr, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Pass(stmt): ... class Break(stmt): ... @@ -239,12 +448,14 @@ class expr(AST): col_offset: int end_lineno: int | None end_col_offset: int | None + def __init__(self, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class BoolOp(expr): if sys.version_info >= (3, 10): __match_args__ = ("op", "values") op: boolop values: list[expr] + def __init__(self, op: boolop, values: list[expr], **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class BinOp(expr): if sys.version_info >= (3, 10): @@ -252,18 +463,21 @@ class BinOp(expr): left: expr op: operator right: expr + def __init__(self, left: expr, op: operator, right: expr, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class UnaryOp(expr): if sys.version_info >= (3, 10): __match_args__ = ("op", "operand") op: unaryop operand: expr + def __init__(self, op: unaryop, operand: expr, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Lambda(expr): if sys.version_info >= (3, 10): __match_args__ = ("args", "body") args: arguments body: expr + def __init__(self, args: arguments, body: expr, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class IfExp(expr): if sys.version_info >= (3, 10): @@ -271,29 +485,34 @@ class IfExp(expr): test: expr body: expr orelse: expr + def __init__(self, test: expr, body: expr, orelse: expr, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Dict(expr): if sys.version_info >= (3, 10): __match_args__ = ("keys", "values") keys: list[expr | None] values: list[expr] + def __init__(self, keys: list[expr | None], values: list[expr], **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Set(expr): if sys.version_info >= (3, 10): __match_args__ = ("elts",) elts: list[expr] + def __init__(self, elts: list[expr], **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class ListComp(expr): if sys.version_info >= (3, 10): __match_args__ = ("elt", "generators") elt: expr generators: list[comprehension] + def __init__(self, elt: expr, generators: list[comprehension], **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class SetComp(expr): if sys.version_info >= (3, 10): __match_args__ = ("elt", "generators") elt: expr generators: list[comprehension] + def __init__(self, elt: expr, generators: list[comprehension], **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class DictComp(expr): if sys.version_info >= (3, 10): @@ -301,27 +520,34 @@ class DictComp(expr): key: expr value: expr generators: list[comprehension] + def __init__( + self, key: expr, value: expr, generators: list[comprehension], **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... class GeneratorExp(expr): if sys.version_info >= (3, 10): __match_args__ = ("elt", "generators") elt: expr generators: list[comprehension] + def __init__(self, elt: expr, generators: list[comprehension], **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Await(expr): if sys.version_info >= (3, 10): __match_args__ = ("value",) value: expr + def __init__(self, value: expr, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Yield(expr): if sys.version_info >= (3, 10): __match_args__ = ("value",) value: expr | None + def __init__(self, value: expr | None = None, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class YieldFrom(expr): if sys.version_info >= (3, 10): __match_args__ = ("value",) value: expr + def __init__(self, value: expr, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Compare(expr): if sys.version_info >= (3, 10): @@ -329,6 +555,9 @@ class Compare(expr): left: expr ops: list[cmpop] comparators: list[expr] + def __init__( + self, left: expr, op: list[cmpop], comparators: list[expr], **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... class Call(expr): if sys.version_info >= (3, 10): @@ -336,6 +565,9 @@ class Call(expr): func: expr args: list[expr] keywords: list[keyword] + def __init__( + self, func: expr, args: list[expr], keywords: list[keyword], **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... class FormattedValue(expr): if sys.version_info >= (3, 10): @@ -343,11 +575,15 @@ class FormattedValue(expr): value: expr conversion: int format_spec: expr | None + def __init__( + self, value: expr, conversion: int, format_spec: expr | None = None, **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... class JoinedStr(expr): if sys.version_info >= (3, 10): __match_args__ = ("values",) values: list[expr] + def __init__(self, values: list[expr], **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Constant(expr): if sys.version_info >= (3, 10): @@ -357,12 +593,14 @@ class Constant(expr): # Aliases for value, for backwards compatibility s: Any n: int | float | complex + def __init__(self, value: Any, kind: str | None = None, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class NamedExpr(expr): if sys.version_info >= (3, 10): __match_args__ = ("target", "value") target: Name value: expr + def __init__(self, target: Name, value: expr, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Attribute(expr): if sys.version_info >= (3, 10): @@ -370,6 +608,9 @@ class Attribute(expr): value: expr attr: _Identifier ctx: expr_context + def __init__( + self, value: expr, attr: _Identifier, ctx: expr_context, **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... if sys.version_info >= (3, 9): _Slice: typing_extensions.TypeAlias = expr @@ -383,13 +624,22 @@ class Slice(_Slice): lower: expr | None upper: expr | None step: expr | None + def __init__( + self, + lower: expr | None = None, + upper: expr | None = None, + step: expr | None = None, + **kwargs: typing_extensions.Unpack[_SliceAttributes], + ) -> None: ... if sys.version_info < (3, 9): class ExtSlice(slice): dims: list[slice] + def __init__(self, dims: list[slice], **kwargs: typing_extensions.Unpack[_SliceAttributes]) -> None: ... class Index(slice): value: expr + def __init__(self, value: expr, **kwargs: typing_extensions.Unpack[_SliceAttributes]) -> None: ... class Subscript(expr): if sys.version_info >= (3, 10): @@ -397,24 +647,30 @@ class Subscript(expr): value: expr slice: _Slice ctx: expr_context + def __init__( + self, value: expr, slice: _Slice, ctx: expr_context, **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... class Starred(expr): if sys.version_info >= (3, 10): __match_args__ = ("value", "ctx") value: expr ctx: expr_context + def __init__(self, value: expr, ctx: expr_context, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Name(expr): if sys.version_info >= (3, 10): __match_args__ = ("id", "ctx") id: _Identifier ctx: expr_context + def __init__(self, id: _Identifier, ctx: expr_context, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class List(expr): if sys.version_info >= (3, 10): __match_args__ = ("elts", "ctx") elts: list[expr] ctx: expr_context + def __init__(self, elts: list[expr], ctx: expr_context, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class Tuple(expr): if sys.version_info >= (3, 10): @@ -424,6 +680,8 @@ class Tuple(expr): if sys.version_info >= (3, 9): dims: list[expr] + def __init__(self, elts: list[expr], ctx: expr_context, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... + class expr_context(AST): ... if sys.version_info < (3, 9): @@ -433,6 +691,7 @@ if sys.version_info < (3, 9): class Suite(mod): body: list[stmt] + def __init__(self, body: list[stmt]) -> None: ... class Del(expr_context): ... class Load(expr_context): ... @@ -478,12 +737,14 @@ class comprehension(AST): iter: expr ifs: list[expr] is_async: int + def __init__(self, target: expr, iter: expr, ifs: list[expr], is_async: int) -> None: ... class excepthandler(AST): lineno: int col_offset: int end_lineno: int | None end_col_offset: int | None + def __init__(self, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class ExceptHandler(excepthandler): if sys.version_info >= (3, 10): @@ -491,6 +752,19 @@ class ExceptHandler(excepthandler): type: expr | None name: _Identifier | None body: list[stmt] + @overload + def __init__( + self, type: expr | None, name: _Identifier | None, body: list[stmt], **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... + @overload + def __init__( + self, + type: expr | None = None, + name: _Identifier | None = None, + *, + body: list[stmt], + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... class arguments(AST): if sys.version_info >= (3, 10): @@ -502,6 +776,41 @@ class arguments(AST): kw_defaults: list[expr | None] kwarg: arg | None defaults: list[expr] + @overload + def __init__( + self, + posonlyargs: list[arg], + args: list[arg], + vararg: arg | None, + kwonlyargs: list[arg], + kw_defaults: list[expr | None], + kwarg: arg | None, + defaults: list[expr], + ) -> None: ... + @overload + def __init__( + self, + posonlyargs: list[arg], + args: list[arg], + vararg: arg | None, + kwonlyargs: list[arg], + kw_defaults: list[expr | None], + kwarg: arg | None = None, + *, + defaults: list[expr], + ) -> None: ... + @overload + def __init__( + self, + posonlyargs: list[arg], + args: list[arg], + vararg: arg | None = None, + *, + kwonlyargs: list[arg], + kw_defaults: list[expr | None], + kwarg: arg | None = None, + defaults: list[expr], + ) -> None: ... class arg(AST): lineno: int @@ -513,6 +822,13 @@ class arg(AST): arg: _Identifier annotation: expr | None type_comment: str | None + def __init__( + self, + arg: _Identifier, + annotation: expr | None = None, + type_comment: str | None = None, + **kwargs: typing_extensions.Unpack[_Attributes], + ) -> None: ... class keyword(AST): lineno: int @@ -523,6 +839,12 @@ class keyword(AST): __match_args__ = ("arg", "value") arg: _Identifier | None value: expr + @overload + def __init__(self, arg: _Identifier | None, value: expr, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... + @overload + def __init__( + self, arg: _Identifier | None = None, *, value: expr, **kwargs: typing_extensions.Unpack[_Attributes] + ) -> None: ... class alias(AST): lineno: int @@ -533,24 +855,28 @@ class alias(AST): __match_args__ = ("name", "asname") name: str asname: _Identifier | None + def __init__(self, name: str, asname: _Identifier | None = None, **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class withitem(AST): if sys.version_info >= (3, 10): __match_args__ = ("context_expr", "optional_vars") context_expr: expr optional_vars: expr | None + def __init__(self, context_expr: expr, optional_vars: expr | None = None) -> None: ... if sys.version_info >= (3, 10): class Match(stmt): __match_args__ = ("subject", "cases") subject: expr cases: list[match_case] + def __init__(self, subject: expr, cases: list[match_case], **kwargs: typing_extensions.Unpack[_Attributes]) -> None: ... class pattern(AST): lineno: int col_offset: int end_lineno: int end_col_offset: int + def __init__(self, **kwargs: typing_extensions.Unpack[_Attributes[int]]) -> None: ... # Without the alias, Pyright complains variables named pattern are recursively defined _Pattern: typing_extensions.TypeAlias = pattern @@ -560,28 +886,43 @@ if sys.version_info >= (3, 10): pattern: _Pattern guard: expr | None body: list[stmt] + @overload + def __init__(self, pattern: _Pattern, guard: expr | None, body: list[stmt]) -> None: ... + @overload + def __init__(self, pattern: _Pattern, guard: expr | None = None, *, body: list[stmt]) -> None: ... class MatchValue(pattern): __match_args__ = ("value",) value: expr + def __init__(self, value: expr, **kwargs: typing_extensions.Unpack[_Attributes[int]]) -> None: ... class MatchSingleton(pattern): __match_args__ = ("value",) value: Literal[True, False] | None + def __init__(self, value: Literal[True, False] | None, **kwargs: typing_extensions.Unpack[_Attributes[int]]) -> None: ... class MatchSequence(pattern): __match_args__ = ("patterns",) patterns: list[pattern] + def __init__(self, patterns: list[pattern], **kwargs: typing_extensions.Unpack[_Attributes[int]]) -> None: ... class MatchStar(pattern): __match_args__ = ("name",) name: _Identifier | None + def __init__(self, name: _Identifier | None, **kwargs: typing_extensions.Unpack[_Attributes[int]]) -> None: ... class MatchMapping(pattern): __match_args__ = ("keys", "patterns", "rest") keys: list[expr] patterns: list[pattern] rest: _Identifier | None + def __init__( + self, + keys: list[expr], + patterns: list[pattern], + rest: _Identifier | None = None, + **kwargs: typing_extensions.Unpack[_Attributes[int]], + ) -> None: ... class MatchClass(pattern): __match_args__ = ("cls", "patterns", "kwd_attrs", "kwd_patterns") @@ -589,15 +930,30 @@ if sys.version_info >= (3, 10): patterns: list[pattern] kwd_attrs: list[_Identifier] kwd_patterns: list[pattern] + def __init__( + self, + cls: expr, + patterns: list[pattern], + kwd_attrs: list[_Identifier], + kwd_patterns: list[pattern], + **kwargs: typing_extensions.Unpack[_Attributes[int]], + ) -> None: ... class MatchAs(pattern): __match_args__ = ("pattern", "name") pattern: _Pattern | None name: _Identifier | None + def __init__( + self, + pattern: _Pattern | None = None, + name: _Identifier | None = None, + **kwargs: typing_extensions.Unpack[_Attributes[int]], + ) -> None: ... class MatchOr(pattern): __match_args__ = ("patterns",) patterns: list[pattern] + def __init__(self, patterns: list[pattern], **kwargs: typing_extensions.Unpack[_Attributes[int]]) -> None: ... if sys.version_info >= (3, 12): class type_param(AST): @@ -605,22 +961,31 @@ if sys.version_info >= (3, 12): col_offset: int end_lineno: int end_col_offset: int + def __init__(self, **kwargs: typing_extensions.Unpack[_Attributes[int]]) -> None: ... class TypeVar(type_param): __match_args__ = ("name", "bound") name: _Identifier bound: expr | None + def __init__( + self, name: _Identifier, bound: expr | None = None, **kwargs: typing_extensions.Unpack[_Attributes[int]] + ) -> None: ... class ParamSpec(type_param): __match_args__ = ("name",) name: _Identifier + def __init__(self, name: _Identifier, **kwargs: typing_extensions.Unpack[_Attributes[int]]) -> None: ... class TypeVarTuple(type_param): __match_args__ = ("name",) name: _Identifier + def __init__(self, name: _Identifier, **kwargs: typing_extensions.Unpack[_Attributes[int]]) -> None: ... class TypeAlias(stmt): __match_args__ = ("name", "type_params", "value") name: Name type_params: list[type_param] value: expr + def __init__( + self, name: Name, type_params: list[type_param], value: expr, **kwargs: typing_extensions.Unpack[_Attributes[int]] + ) -> None: ...