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,16 +1,19 @@
from collections.abc import Iterator
from lib2to3.pgen2.grammar import Grammar
from typing import Any
from typing_extensions import Self, TypeAlias
from _typeshed import Incomplete, SupportsGetItem, SupportsLenAndGetItem, Unused
from abc import abstractmethod
from collections.abc import Iterable, Iterator, MutableSequence
from typing_extensions import Final, Self, TypeAlias
from .fixer_base import BaseFix
from .pgen2.grammar import Grammar
_NL: TypeAlias = Node | Leaf
_Context: TypeAlias = tuple[str, int, int]
_Results: TypeAlias = dict[str, _NL]
_RawNode: TypeAlias = tuple[int, str, _Context, list[_NL] | None]
HUGE: int
HUGE: Final = 0x7FFFFFFF
def type_repr(type_num: int) -> str: ...
def type_repr(type_num: int) -> str | int: ...
class Base:
type: int
@@ -20,10 +23,14 @@ class Base:
was_changed: bool
was_checked: bool
def __eq__(self, other: object) -> bool: ...
def _eq(self, other: Self) -> bool: ...
@abstractmethod
def _eq(self, other: Base) -> bool: ...
@abstractmethod
def clone(self) -> Self: ...
def post_order(self) -> Iterator[_NL]: ...
def pre_order(self) -> Iterator[_NL]: ...
@abstractmethod
def post_order(self) -> Iterator[Self]: ...
@abstractmethod
def pre_order(self) -> Iterator[Self]: ...
def replace(self, new: _NL | list[_NL]) -> None: ...
def get_lineno(self) -> int: ...
def changed(self) -> None: ...
@@ -37,15 +44,23 @@ class Base:
def get_suffix(self) -> str: ...
class Node(Base):
fixers_applied: list[Any]
fixers_applied: MutableSequence[BaseFix] | None
# Is Unbound until set in refactor.RefactoringTool
future_features: frozenset[Incomplete]
# Is Unbound until set in pgen2.parse.Parser.pop
used_names: set[str]
def __init__(
self,
type: int,
children: list[_NL],
context: Any | None = None,
children: Iterable[_NL],
context: Unused = None,
prefix: str | None = None,
fixers_applied: list[Any] | None = None,
fixers_applied: MutableSequence[BaseFix] | None = None,
) -> None: ...
def _eq(self, other: Base) -> bool: ...
def clone(self) -> Node: ...
def post_order(self) -> Iterator[Self]: ...
def pre_order(self) -> Iterator[Self]: ...
def set_child(self, i: int, child: _NL) -> None: ...
def insert_child(self, i: int, child: _NL) -> None: ...
def append_child(self, child: _NL) -> None: ...
@@ -55,10 +70,19 @@ class Leaf(Base):
lineno: int
column: int
value: str
fixers_applied: list[Any]
fixers_applied: MutableSequence[BaseFix]
def __init__(
self, type: int, value: str, context: _Context | None = None, prefix: str | None = None, fixers_applied: list[Any] = []
self,
type: int,
value: str,
context: _Context | None = None,
prefix: str | None = None,
fixers_applied: MutableSequence[BaseFix] = [],
) -> None: ...
def _eq(self, other: Base) -> bool: ...
def clone(self) -> Leaf: ...
def post_order(self) -> Iterator[Self]: ...
def pre_order(self) -> Iterator[Self]: ...
def __unicode__(self) -> str: ...
def convert(gr: Grammar, raw_node: _RawNode) -> _NL: ...
@@ -69,8 +93,8 @@ class BasePattern:
name: str | None
def optimize(self) -> BasePattern: ... # sic, subclasses are free to optimize themselves into different patterns
def match(self, node: _NL, results: _Results | None = None) -> bool: ...
def match_seq(self, nodes: list[_NL], results: _Results | None = None) -> bool: ...
def generate_matches(self, nodes: list[_NL]) -> Iterator[tuple[int, _Results]]: ...
def match_seq(self, nodes: SupportsLenAndGetItem[_NL], results: _Results | None = None) -> bool: ...
def generate_matches(self, nodes: SupportsGetItem[int, _NL]) -> Iterator[tuple[int, _Results]]: ...
class LeafPattern(BasePattern):
def __init__(self, type: int | None = None, content: str | None = None, name: str | None = None) -> None: ...
@@ -87,4 +111,6 @@ class WildcardPattern(BasePattern):
class NegatedPattern(BasePattern):
def __init__(self, content: str | None = None) -> None: ...
def generate_matches(patterns: list[BasePattern], nodes: list[_NL]) -> Iterator[tuple[int, _Results]]: ...
def generate_matches(
patterns: SupportsGetItem[int | slice, BasePattern] | None, nodes: SupportsGetItem[int | slice, _NL]
) -> Iterator[tuple[int, _Results]]: ...