mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-23 11:32:07 +08:00
change ast files to use new union syntax (#5880)
This commit is contained in:
@@ -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]: ...
|
||||
|
||||
Reference in New Issue
Block a user