change ast files to use new union syntax (#5880)

This commit is contained in:
Akuli
2021-08-08 16:47:33 +03:00
committed by GitHub
parent 1154218a0e
commit 1409f6e892
4 changed files with 117 additions and 117 deletions

View File

@@ -1,6 +1,6 @@
import sys
import typing
from typing import Any, ClassVar, Optional
from typing import Any, ClassVar
from typing_extensions import Literal
PyCF_ONLY_AST: int
@@ -18,9 +18,9 @@ class AST:
lineno: int
col_offset: int
if sys.version_info >= (3, 8):
end_lineno: Optional[int]
end_col_offset: Optional[int]
type_comment: Optional[str]
end_lineno: int | None
end_col_offset: int | None
type_comment: str | None
class mod(AST): ...
@@ -50,14 +50,14 @@ class FunctionDef(stmt):
args: arguments
body: typing.List[stmt]
decorator_list: typing.List[expr]
returns: Optional[expr]
returns: expr | None
class AsyncFunctionDef(stmt):
name: _identifier
args: arguments
body: typing.List[stmt]
decorator_list: typing.List[expr]
returns: Optional[expr]
returns: expr | None
class ClassDef(stmt):
name: _identifier
@@ -67,7 +67,7 @@ class ClassDef(stmt):
decorator_list: typing.List[expr]
class Return(stmt):
value: Optional[expr]
value: expr | None
class Delete(stmt):
targets: typing.List[expr]
@@ -84,7 +84,7 @@ class AugAssign(stmt):
class AnnAssign(stmt):
target: expr
annotation: expr
value: Optional[expr]
value: expr | None
simple: int
class For(stmt):
@@ -118,8 +118,8 @@ class AsyncWith(stmt):
body: typing.List[stmt]
class Raise(stmt):
exc: Optional[expr]
cause: Optional[expr]
exc: expr | None
cause: expr | None
class Try(stmt):
body: typing.List[stmt]
@@ -129,13 +129,13 @@ class Try(stmt):
class Assert(stmt):
test: expr
msg: Optional[expr]
msg: expr | None
class Import(stmt):
names: typing.List[alias]
class ImportFrom(stmt):
module: Optional[_identifier]
module: _identifier | None
names: typing.List[alias]
level: int
@@ -176,7 +176,7 @@ class IfExp(expr):
orelse: expr
class Dict(expr):
keys: typing.List[Optional[expr]]
keys: typing.List[expr | None]
values: typing.List[expr]
class Set(expr):
@@ -203,7 +203,7 @@ class Await(expr):
value: expr
class Yield(expr):
value: Optional[expr]
value: expr | None
class YieldFrom(expr):
value: expr
@@ -220,8 +220,8 @@ class Call(expr):
class FormattedValue(expr):
value: expr
conversion: Optional[int]
format_spec: Optional[expr]
conversion: int | None
format_spec: expr | None
class JoinedStr(expr):
values: typing.List[expr]
@@ -239,7 +239,7 @@ if sys.version_info < (3, 8):
class Constant(expr):
value: Any # None, str, bytes, bool, int, float, complex, Ellipsis
kind: Optional[str]
kind: str | None
# Aliases for value, for backwards compatibility
s: Any
n: complex
@@ -261,9 +261,9 @@ else:
_SliceT = slice
class Slice(_SliceT):
lower: Optional[expr]
upper: Optional[expr]
step: Optional[expr]
lower: expr | None
upper: expr | None
step: expr | None
if sys.version_info < (3, 9):
class ExtSlice(slice):
@@ -347,35 +347,35 @@ class comprehension(AST):
class excepthandler(AST): ...
class ExceptHandler(excepthandler):
type: Optional[expr]
name: Optional[_identifier]
type: expr | None
name: _identifier | None
body: typing.List[stmt]
class arguments(AST):
if sys.version_info >= (3, 8):
posonlyargs: typing.List[arg]
args: typing.List[arg]
vararg: Optional[arg]
vararg: arg | None
kwonlyargs: typing.List[arg]
kw_defaults: typing.List[Optional[expr]]
kwarg: Optional[arg]
kw_defaults: typing.List[expr | None]
kwarg: arg | None
defaults: typing.List[expr]
class arg(AST):
arg: _identifier
annotation: Optional[expr]
annotation: expr | None
class keyword(AST):
arg: Optional[_identifier]
arg: _identifier | None
value: expr
class alias(AST):
name: _identifier
asname: Optional[_identifier]
asname: _identifier | None
class withitem(AST):
context_expr: expr
optional_vars: Optional[expr]
optional_vars: expr | None
if sys.version_info >= (3, 10):
class Match(stmt):
@@ -386,7 +386,7 @@ if sys.version_info >= (3, 10):
_pattern = pattern
class match_case(AST):
pattern: _pattern
guard: Optional[expr]
guard: expr | None
body: typing.List[stmt]
class MatchValue(pattern):
value: expr
@@ -395,18 +395,18 @@ if sys.version_info >= (3, 10):
class MatchSequence(pattern):
patterns: typing.List[pattern]
class MatchStar(pattern):
name: Optional[_identifier]
name: _identifier | None
class MatchMapping(pattern):
keys: typing.List[expr]
patterns: typing.List[pattern]
rest: Optional[_identifier]
rest: _identifier | None
class MatchClass(pattern):
cls: expr
patterns: typing.List[pattern]
kwd_attrs: typing.List[_identifier]
kwd_patterns: typing.List[pattern]
class MatchAs(pattern):
pattern: Optional[_pattern]
name: Optional[_identifier]
pattern: _pattern | None
name: _identifier | None
class MatchOr(pattern):
patterns: typing.List[pattern]

View File

@@ -8,7 +8,7 @@
# sys.
import sys
import typing as _typing
from typing import Any, Iterator, Optional, TypeVar, Union, overload
from typing import Any, Iterator, TypeVar, overload
from typing_extensions import Literal
from _ast import * # type: ignore
@@ -150,7 +150,7 @@ class NodeVisitor:
class NodeTransformer(NodeVisitor):
def generic_visit(self, node: AST) -> AST: ...
# TODO: Override the visit_* methods with better return types.
# The usual return type is Optional[AST], but Iterable[AST]
# 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)
@@ -158,28 +158,28 @@ _T = TypeVar("_T", bound=AST)
if sys.version_info >= (3, 8):
@overload
def parse(
source: Union[str, bytes],
filename: Union[str, bytes] = ...,
source: str | bytes,
filename: str | bytes = ...,
mode: Literal["exec"] = ...,
*,
type_comments: bool = ...,
feature_version: Union[None, int, _typing.Tuple[int, int]] = ...,
feature_version: None | int | _typing.Tuple[int, int] = ...,
) -> Module: ...
@overload
def parse(
source: Union[str, bytes],
filename: Union[str, bytes] = ...,
source: str | bytes,
filename: str | bytes = ...,
mode: str = ...,
*,
type_comments: bool = ...,
feature_version: Union[None, int, _typing.Tuple[int, int]] = ...,
feature_version: None | int | _typing.Tuple[int, int] = ...,
) -> AST: ...
else:
@overload
def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: Literal["exec"] = ...) -> Module: ...
def parse(source: str | bytes, filename: str | bytes = ..., mode: Literal["exec"] = ...) -> Module: ...
@overload
def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...) -> AST: ...
def parse(source: str | bytes, filename: str | bytes = ..., mode: str = ...) -> AST: ...
if sys.version_info >= (3, 9):
def unparse(ast_obj: AST) -> str: ...
@@ -188,20 +188,20 @@ def copy_location(new_node: _T, old_node: AST) -> _T: ...
if sys.version_info >= (3, 9):
def dump(
node: AST, annotate_fields: bool = ..., include_attributes: bool = ..., *, indent: Union[int, str, None] = ...
node: AST, annotate_fields: bool = ..., include_attributes: bool = ..., *, indent: int | str | None = ...
) -> str: ...
else:
def dump(node: AST, annotate_fields: bool = ..., include_attributes: bool = ...) -> str: ...
def fix_missing_locations(node: _T) -> _T: ...
def get_docstring(node: AST, clean: bool = ...) -> Optional[str]: ...
def get_docstring(node: AST, clean: bool = ...) -> str | None: ...
def increment_lineno(node: _T, n: int = ...) -> _T: ...
def iter_child_nodes(node: AST) -> Iterator[AST]: ...
def iter_fields(node: AST) -> Iterator[_typing.Tuple[str, Any]]: ...
def literal_eval(node_or_string: Union[str, AST]) -> Any: ...
def literal_eval(node_or_string: str | AST) -> Any: ...
if sys.version_info >= (3, 8):
def get_source_segment(source: str, node: AST, *, padded: bool = ...) -> Optional[str]: ...
def get_source_segment(source: str, node: AST, *, padded: bool = ...) -> str | None: ...
def walk(node: AST) -> Iterator[AST]: ...