Switch to PEP-604 syntax in python2 stubs (#5915)

Signed-off-by: oleg.hoefling <oleg.hoefling@gmail.com>
This commit is contained in:
Oleg Höfling
2021-08-14 11:12:30 +02:00
committed by GitHub
parent 431c4f7fc1
commit ff63953188
235 changed files with 2473 additions and 2768 deletions

View File

@@ -2,19 +2,19 @@ from _typeshed import StrPath
from lib2to3.pgen2.grammar import Grammar
from lib2to3.pytree import _NL, _Convert
from logging import Logger
from typing import IO, Any, Iterable, Optional, Text
from typing import IO, Any, Iterable, Text
class Driver:
grammar: Grammar
logger: Logger
convert: _Convert
def __init__(self, grammar: Grammar, convert: Optional[_Convert] = ..., logger: Optional[Logger] = ...) -> None: ...
def __init__(self, grammar: Grammar, convert: _Convert | None = ..., logger: Logger | None = ...) -> None: ...
def parse_tokens(self, tokens: Iterable[Any], debug: bool = ...) -> _NL: ...
def parse_stream_raw(self, stream: IO[Text], debug: bool = ...) -> _NL: ...
def parse_stream(self, stream: IO[Text], debug: bool = ...) -> _NL: ...
def parse_file(self, filename: StrPath, encoding: Optional[Text] = ..., debug: bool = ...) -> _NL: ...
def parse_file(self, filename: StrPath, encoding: Text | None = ..., debug: bool = ...) -> _NL: ...
def parse_string(self, text: Text, debug: bool = ...) -> _NL: ...
def load_grammar(
gt: Text = ..., gp: Optional[Text] = ..., save: bool = ..., force: bool = ..., logger: Optional[Logger] = ...
gt: Text = ..., gp: Text | None = ..., save: bool = ..., force: bool = ..., logger: Logger | None = ...
) -> Grammar: ...

View File

@@ -1,26 +1,26 @@
from lib2to3.pgen2.grammar import _DFAS, Grammar
from lib2to3.pytree import _NL, _Convert, _RawNode
from typing import Any, List, Optional, Sequence, Set, Text, Tuple
from typing import Any, List, Sequence, Set, Text, Tuple
_Context = Sequence[Any]
class ParseError(Exception):
msg: Text
type: int
value: Optional[Text]
value: Text | None
context: _Context
def __init__(self, msg: Text, type: int, value: Optional[Text], context: _Context) -> None: ...
def __init__(self, msg: Text, type: int, value: Text | None, context: _Context) -> None: ...
class Parser:
grammar: Grammar
convert: _Convert
stack: List[Tuple[_DFAS, int, _RawNode]]
rootnode: Optional[_NL]
rootnode: _NL | None
used_names: Set[Text]
def __init__(self, grammar: Grammar, convert: Optional[_Convert] = ...) -> None: ...
def setup(self, start: Optional[int] = ...) -> None: ...
def addtoken(self, type: int, value: Optional[Text], context: _Context) -> bool: ...
def classify(self, type: int, value: Optional[Text], context: _Context) -> int: ...
def shift(self, type: int, value: Optional[Text], newstate: int, context: _Context) -> None: ...
def __init__(self, grammar: Grammar, convert: _Convert | None = ...) -> None: ...
def setup(self, start: int | None = ...) -> None: ...
def addtoken(self, type: int, value: Text | None, context: _Context) -> bool: ...
def classify(self, type: int, value: Text | None, context: _Context) -> int: ...
def shift(self, type: int, value: Text | None, newstate: int, context: _Context) -> None: ...
def push(self, type: int, newdfa: _DFAS, newstate: int, context: _Context) -> None: ...
def pop(self) -> None: ...

View File

@@ -1,7 +1,7 @@
from _typeshed import StrPath
from lib2to3.pgen2 import grammar
from lib2to3.pgen2.tokenize import _TokenInfo
from typing import IO, Any, Dict, Iterable, Iterator, List, NoReturn, Optional, Text, Tuple
from typing import IO, Any, Dict, Iterable, Iterator, List, NoReturn, Text, Tuple
class PgenGrammar(grammar.Grammar): ...
@@ -10,7 +10,7 @@ class ParserGenerator:
stream: IO[Text]
generator: Iterator[_TokenInfo]
first: Dict[Text, Dict[Text, int]]
def __init__(self, filename: StrPath, stream: Optional[IO[Text]] = ...) -> None: ...
def __init__(self, filename: StrPath, stream: IO[Text] | None = ...) -> None: ...
def make_grammar(self) -> PgenGrammar: ...
def make_first(self, c: PgenGrammar, name: Text) -> Dict[int, int]: ...
def make_label(self, c: PgenGrammar, label: Text) -> int: ...
@@ -25,14 +25,14 @@ class ParserGenerator:
def parse_alt(self) -> Tuple[NFAState, NFAState]: ...
def parse_item(self) -> Tuple[NFAState, NFAState]: ...
def parse_atom(self) -> Tuple[NFAState, NFAState]: ...
def expect(self, type: int, value: Optional[Any] = ...) -> Text: ...
def expect(self, type: int, value: Any | None = ...) -> Text: ...
def gettoken(self) -> None: ...
def raise_error(self, msg: str, *args: Any) -> NoReturn: ...
class NFAState:
arcs: List[Tuple[Optional[Text], NFAState]]
arcs: List[Tuple[Text | None, NFAState]]
def __init__(self) -> None: ...
def addarc(self, next: NFAState, label: Optional[Text] = ...) -> None: ...
def addarc(self, next: NFAState, label: Text | None = ...) -> None: ...
class DFAState:
nfaset: Dict[NFAState, Any]

View File

@@ -14,7 +14,7 @@ def type_repr(type_num: int) -> Text: ...
class Base:
type: int
parent: Optional[Node]
parent: Node | None
prefix: Text
children: List[_NL]
was_changed: bool
@@ -24,14 +24,14 @@ class Base:
def clone(self: _P) -> _P: ...
def post_order(self) -> Iterator[_NL]: ...
def pre_order(self) -> Iterator[_NL]: ...
def replace(self, new: Union[_NL, List[_NL]]) -> None: ...
def replace(self, new: _NL | List[_NL]) -> None: ...
def get_lineno(self) -> int: ...
def changed(self) -> None: ...
def remove(self) -> Optional[int]: ...
def remove(self) -> int | None: ...
@property
def next_sibling(self) -> Optional[_NL]: ...
def next_sibling(self) -> _NL | None: ...
@property
def prev_sibling(self) -> Optional[_NL]: ...
def prev_sibling(self) -> _NL | None: ...
def leaves(self) -> Iterator[Leaf]: ...
def depth(self) -> int: ...
def get_suffix(self) -> Text: ...
@@ -44,9 +44,9 @@ class Node(Base):
self,
type: int,
children: List[_NL],
context: Optional[Any] = ...,
prefix: Optional[Text] = ...,
fixers_applied: Optional[List[Any]] = ...,
context: Any | None = ...,
prefix: Text | None = ...,
fixers_applied: List[Any] | None = ...,
) -> None: ...
def set_child(self, i: int, child: _NL) -> None: ...
def insert_child(self, i: int, child: _NL) -> None: ...
@@ -58,38 +58,33 @@ class Leaf(Base):
value: Text
fixers_applied: List[Any]
def __init__(
self,
type: int,
value: Text,
context: Optional[_Context] = ...,
prefix: Optional[Text] = ...,
fixers_applied: List[Any] = ...,
self, type: int, value: Text, context: _Context | None = ..., prefix: Text | None = ..., fixers_applied: List[Any] = ...
) -> None: ...
def convert(gr: Grammar, raw_node: _RawNode) -> _NL: ...
class BasePattern:
type: int
content: Optional[Text]
name: Optional[Text]
content: Text | None
name: Text | None
def optimize(self) -> BasePattern: ... # sic, subclasses are free to optimize themselves into different patterns
def match(self, node: _NL, results: Optional[_Results] = ...) -> bool: ...
def match_seq(self, nodes: List[_NL], results: Optional[_Results] = ...) -> bool: ...
def match(self, node: _NL, results: _Results | None = ...) -> bool: ...
def match_seq(self, nodes: List[_NL], results: _Results | None = ...) -> bool: ...
def generate_matches(self, nodes: List[_NL]) -> Iterator[Tuple[int, _Results]]: ...
class LeafPattern(BasePattern):
def __init__(self, type: Optional[int] = ..., content: Optional[Text] = ..., name: Optional[Text] = ...) -> None: ...
def __init__(self, type: int | None = ..., content: Text | None = ..., name: Text | None = ...) -> None: ...
class NodePattern(BasePattern):
wildcards: bool
def __init__(self, type: Optional[int] = ..., content: Optional[Text] = ..., name: Optional[Text] = ...) -> None: ...
def __init__(self, type: int | None = ..., content: Text | None = ..., name: Text | None = ...) -> None: ...
class WildcardPattern(BasePattern):
min: int
max: int
def __init__(self, content: Optional[Text] = ..., min: int = ..., max: int = ..., name: Optional[Text] = ...) -> None: ...
def __init__(self, content: Text | None = ..., min: int = ..., max: int = ..., name: Text | None = ...) -> None: ...
class NegatedPattern(BasePattern):
def __init__(self, content: Optional[Text] = ...) -> None: ...
def __init__(self, content: Text | None = ...) -> None: ...
def generate_matches(patterns: List[BasePattern], nodes: List[_NL]) -> Iterator[Tuple[int, _Results]]: ...