Use TypeAlias where possible for type aliases (#7630)

This commit is contained in:
Alex Waygood
2022-04-16 02:01:00 +01:00
committed by GitHub
parent c0e6dd3f3f
commit 740193a8fc
218 changed files with 760 additions and 625 deletions

View File

@@ -1,8 +1,9 @@
from _typeshed import Self, StrPath
from typing_extensions import TypeAlias
_Label = tuple[int, str | None]
_DFA = list[list[tuple[int, int]]]
_DFAS = tuple[_DFA, dict[int, int]]
_Label: TypeAlias = tuple[int, str | None]
_DFA: TypeAlias = list[list[tuple[int, int]]]
_DFAS: TypeAlias = tuple[_DFA, dict[int, int]]
class Grammar:
symbol2number: dict[str, int]

View File

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

View File

@@ -1,6 +1,7 @@
import sys
from lib2to3.pgen2.token import *
from typing import Callable, Iterable, Iterator
from typing_extensions import TypeAlias
if sys.version_info >= (3, 8):
__all__ = [
@@ -146,9 +147,9 @@ else:
"untokenize",
]
_Coord = tuple[int, int]
_TokenEater = Callable[[int, str, _Coord, _Coord, str], None]
_TokenInfo = tuple[int, str, _Coord, _Coord, str]
_Coord: TypeAlias = tuple[int, int]
_TokenEater: TypeAlias = Callable[[int, str, _Coord, _Coord, str], None]
_TokenInfo: TypeAlias = tuple[int, str, _Coord, _Coord, str]
class TokenError(Exception): ...
class StopTokenizing(Exception): ...

View File

@@ -1,12 +1,13 @@
from _typeshed import Self
from lib2to3.pgen2.grammar import Grammar
from typing import Any, Callable, Iterator
from typing_extensions import TypeAlias
_NL = Node | Leaf
_Context = tuple[str, int, int]
_Results = dict[str, _NL]
_RawNode = tuple[int, str, _Context, list[_NL] | None]
_Convert = Callable[[Grammar, _RawNode], Any]
_NL: TypeAlias = Node | Leaf
_Context: TypeAlias = tuple[str, int, int]
_Results: TypeAlias = dict[str, _NL]
_RawNode: TypeAlias = tuple[int, str, _Context, list[_NL] | None]
_Convert: TypeAlias = Callable[[Grammar, _RawNode], Any]
HUGE: int