Add fixers to lib2to3 (#10003)

This commit is contained in:
Avasam
2023-04-28 00:56:56 -04:00
committed by GitHub
parent a7748a9dd1
commit fb4bf034f3
65 changed files with 833 additions and 77 deletions

View File

@@ -1,8 +1,9 @@
from collections.abc import Callable
from lib2to3.pgen2.grammar import Grammar
from lib2to3.pytree import _RawNode
from typing import Any
from typing_extensions import TypeAlias
from ..pytree import _RawNode
from .grammar import Grammar
# This is imported in several lib2to3/pgen2 submodules
_Convert: TypeAlias = Callable[[Grammar, _RawNode], Any] # noqa: Y047

View File

@@ -1,10 +1,11 @@
from _typeshed import StrPath
from collections.abc import Iterable
from lib2to3.pgen2 import _Convert
from lib2to3.pgen2.grammar import Grammar
from lib2to3.pytree import _NL
from logging import Logger
from typing import IO, Any
from typing import IO
from ..pytree import _NL
from . import _Convert
from .grammar import Grammar
__all__ = ["Driver", "load_grammar"]
@@ -13,7 +14,9 @@ class Driver:
logger: Logger
convert: _Convert
def __init__(self, grammar: Grammar, convert: _Convert | None = None, logger: Logger | None = None) -> None: ...
def parse_tokens(self, tokens: Iterable[Any], debug: bool = False) -> _NL: ...
def parse_tokens(
self, tokens: Iterable[tuple[int, str, tuple[int, int], tuple[int, int], str]], debug: bool = False
) -> _NL: ...
def parse_stream_raw(self, stream: IO[str], debug: bool = False) -> _NL: ...
def parse_stream(self, stream: IO[str], debug: bool = False) -> _NL: ...
def parse_file(self, filename: StrPath, encoding: str | None = None, debug: bool = False) -> _NL: ...

View File

@@ -1,11 +1,12 @@
from _typeshed import Incomplete
from collections.abc import Sequence
from lib2to3.pgen2 import _Convert
from lib2to3.pgen2.grammar import _DFAS, Grammar
from lib2to3.pytree import _NL, _RawNode
from typing import Any
from typing_extensions import TypeAlias
_Context: TypeAlias = Sequence[Any]
from ..pytree import _NL, _RawNode
from . import _Convert
from .grammar import _DFAS, Grammar
_Context: TypeAlias = Sequence[Incomplete]
class ParseError(Exception):
msg: str

View File

@@ -1,8 +1,9 @@
from _typeshed import StrPath
from _typeshed import Incomplete, StrPath
from collections.abc import Iterable, Iterator
from lib2to3.pgen2 import grammar
from lib2to3.pgen2.tokenize import _TokenInfo
from typing import IO, Any, NoReturn
from typing import IO, NoReturn, overload
from . import grammar
from .tokenize import _TokenInfo
class PgenGrammar(grammar.Grammar): ...
@@ -26,19 +27,22 @@ 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: Any | None = None) -> str: ...
def expect(self, type: int, value: str | None = None) -> str: ...
def gettoken(self) -> None: ...
def raise_error(self, msg: str, *args: Any) -> NoReturn: ...
@overload
def raise_error(self, msg: object) -> NoReturn: ...
@overload
def raise_error(self, msg: str, *args: object) -> NoReturn: ...
class NFAState:
arcs: list[tuple[str | None, NFAState]]
def addarc(self, next: NFAState, label: str | None = None) -> None: ...
class DFAState:
nfaset: dict[NFAState, Any]
nfaset: dict[NFAState, Incomplete]
isfinal: bool
arcs: dict[str, DFAState]
def __init__(self, nfaset: dict[NFAState, Any], final: NFAState) -> None: ...
def __init__(self, nfaset: dict[NFAState, Incomplete], final: NFAState) -> None: ...
def addarc(self, next: DFAState, label: str) -> None: ...
def unifystate(self, old: DFAState, new: DFAState) -> None: ...
def __eq__(self, other: DFAState) -> bool: ... # type: ignore[override]

View File

@@ -1,7 +1,8 @@
from collections.abc import Callable, Iterable, Iterator
from lib2to3.pgen2.token import *
from typing_extensions import TypeAlias
from .token import *
__all__ = [
"AMPER",
"AMPEREQUAL",