Skip to content

Commit fb4bf03

Browse files
authored
Add fixers to lib2to3 (#10003)
1 parent a7748a9 commit fb4bf03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+833
-77
lines changed

pyrightconfig.stricter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"stubs/**/@tests/test_cases",
1111
"stdlib/distutils/command",
1212
"stdlib/distutils/dist.pyi",
13-
"stdlib/lib2to3/refactor.pyi",
13+
"stdlib/lib2to3/fixes/*.pyi",
1414
"stdlib/_tkinter.pyi",
1515
"stdlib/tkinter/__init__.pyi",
1616
"stdlib/tkinter/filedialog.pyi",

stdlib/lib2to3/btm_matcher.pyi

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from _typeshed import Incomplete, SupportsGetItem
2+
from collections import defaultdict
3+
from collections.abc import Iterable
4+
5+
from .fixer_base import BaseFix
6+
from .pytree import Leaf, Node
7+
8+
class BMNode:
9+
count: Incomplete
10+
transition_table: Incomplete
11+
fixers: Incomplete
12+
id: Incomplete
13+
content: str
14+
def __init__(self) -> None: ...
15+
16+
class BottomMatcher:
17+
match: Incomplete
18+
root: Incomplete
19+
nodes: Incomplete
20+
fixers: Incomplete
21+
logger: Incomplete
22+
def __init__(self) -> None: ...
23+
def add_fixer(self, fixer: BaseFix) -> None: ...
24+
def add(self, pattern: SupportsGetItem[int | slice, Incomplete] | None, start: BMNode) -> list[BMNode]: ...
25+
def run(self, leaves: Iterable[Leaf]) -> defaultdict[BaseFix, list[Node | Leaf]]: ...
26+
def print_ac(self) -> None: ...
27+
28+
def type_repr(type_num: int) -> str | int: ...

stdlib/lib2to3/fixer_base.pyi

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from _typeshed import Incomplete, StrPath
2+
from abc import ABCMeta, abstractmethod
3+
from collections.abc import MutableMapping
4+
from typing import ClassVar, TypeVar
5+
from typing_extensions import Literal
6+
7+
from .pytree import Base, Leaf, Node
8+
9+
_N = TypeVar("_N", bound=Base)
10+
11+
class BaseFix:
12+
PATTERN: ClassVar[str | None]
13+
pattern: Incomplete | None
14+
pattern_tree: Incomplete | None
15+
options: Incomplete | None
16+
filename: Incomplete | None
17+
numbers: Incomplete
18+
used_names: Incomplete
19+
order: ClassVar[Literal["post", "pre"]]
20+
explicit: ClassVar[bool]
21+
run_order: ClassVar[int]
22+
keep_line_order: ClassVar[bool]
23+
BM_compatible: ClassVar[bool]
24+
syms: Incomplete
25+
log: Incomplete
26+
def __init__(self, options: MutableMapping[str, Incomplete], log: list[str]) -> None: ...
27+
def compile_pattern(self) -> None: ...
28+
def set_filename(self, filename: StrPath) -> None: ...
29+
def match(self, node: _N) -> Literal[False] | dict[str, _N]: ...
30+
@abstractmethod
31+
def transform(self, node: Base, results: dict[str, Base]) -> Node | Leaf | None: ...
32+
def new_name(self, template: str = "xxx_todo_changeme") -> str: ...
33+
first_log: bool
34+
def log_message(self, message: str) -> None: ...
35+
def cannot_convert(self, node: Base, reason: str | None = None) -> None: ...
36+
def warning(self, node: Base, reason: str) -> None: ...
37+
def start_tree(self, tree: Node, filename: StrPath) -> None: ...
38+
def finish_tree(self, tree: Node, filename: StrPath) -> None: ...
39+
40+
class ConditionalFix(BaseFix, metaclass=ABCMeta):
41+
skip_on: ClassVar[str | None]
42+
def start_tree(self, __tree: Node, __filename: StrPath) -> None: ...
43+
def should_skip(self, node: Base) -> bool: ...

stdlib/lib2to3/fixes/__init__.pyi

Whitespace-only changes.

stdlib/lib2to3/fixes/fix_apply.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
class FixApply(fixer_base.BaseFix):
7+
BM_compatible: ClassVar[Literal[True]]
8+
PATTERN: ClassVar[str]
9+
def transform(self, node, results): ...

stdlib/lib2to3/fixes/fix_asserts.pyi

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from ..fixer_base import BaseFix
5+
6+
NAMES: dict[str, str]
7+
8+
class FixAsserts(BaseFix):
9+
BM_compatible: ClassVar[Literal[False]]
10+
PATTERN: ClassVar[str]
11+
def transform(self, node, results) -> None: ...
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
class FixBasestring(fixer_base.BaseFix):
7+
BM_compatible: ClassVar[Literal[True]]
8+
PATTERN: ClassVar[Literal["'basestring'"]]
9+
def transform(self, node, results): ...

stdlib/lib2to3/fixes/fix_buffer.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
class FixBuffer(fixer_base.BaseFix):
7+
BM_compatible: ClassVar[Literal[True]]
8+
PATTERN: ClassVar[str]
9+
def transform(self, node, results) -> None: ...

stdlib/lib2to3/fixes/fix_dict.pyi

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from _typeshed import Incomplete
2+
from typing import ClassVar
3+
from typing_extensions import Literal
4+
5+
from .. import fixer_base
6+
7+
iter_exempt: set[str]
8+
9+
class FixDict(fixer_base.BaseFix):
10+
BM_compatible: ClassVar[Literal[True]]
11+
PATTERN: ClassVar[str]
12+
def transform(self, node, results): ...
13+
P1: ClassVar[str]
14+
p1: ClassVar[Incomplete]
15+
P2: ClassVar[str]
16+
p2: ClassVar[Incomplete]
17+
def in_special_context(self, node, isiter): ...

stdlib/lib2to3/fixes/fix_except.pyi

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from collections.abc import Generator, Iterable
2+
from typing import ClassVar, TypeVar
3+
from typing_extensions import Literal
4+
5+
from .. import fixer_base
6+
from ..pytree import Base
7+
8+
_N = TypeVar("_N", bound=Base)
9+
10+
def find_excepts(nodes: Iterable[_N]) -> Generator[tuple[_N, _N], None, None]: ...
11+
12+
class FixExcept(fixer_base.BaseFix):
13+
BM_compatible: ClassVar[Literal[True]]
14+
PATTERN: ClassVar[str]
15+
def transform(self, node, results): ...

stdlib/lib2to3/fixes/fix_exec.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
class FixExec(fixer_base.BaseFix):
7+
BM_compatible: ClassVar[Literal[True]]
8+
PATTERN: ClassVar[str]
9+
def transform(self, node, results): ...

stdlib/lib2to3/fixes/fix_execfile.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
class FixExecfile(fixer_base.BaseFix):
7+
BM_compatible: ClassVar[Literal[True]]
8+
PATTERN: ClassVar[str]
9+
def transform(self, node, results): ...

stdlib/lib2to3/fixes/fix_exitfunc.pyi

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from _typeshed import Incomplete, StrPath
2+
from lib2to3 import fixer_base
3+
from typing import ClassVar
4+
from typing_extensions import Literal
5+
6+
from ..pytree import Node
7+
8+
class FixExitfunc(fixer_base.BaseFix):
9+
BM_compatible: ClassVar[Literal[True]]
10+
PATTERN: ClassVar[str]
11+
def __init__(self, *args) -> None: ...
12+
sys_import: Incomplete | None
13+
def start_tree(self, tree: Node, filename: StrPath) -> None: ...
14+
def transform(self, node, results) -> None: ...

stdlib/lib2to3/fixes/fix_filter.pyi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
class FixFilter(fixer_base.ConditionalFix):
7+
BM_compatible: ClassVar[Literal[True]]
8+
PATTERN: ClassVar[str]
9+
skip_on: ClassVar[Literal["future_builtins.filter"]]
10+
def transform(self, node, results): ...
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
class FixFuncattrs(fixer_base.BaseFix):
7+
BM_compatible: ClassVar[Literal[True]]
8+
PATTERN: ClassVar[str]
9+
def transform(self, node, results) -> None: ...

stdlib/lib2to3/fixes/fix_future.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
class FixFuture(fixer_base.BaseFix):
7+
BM_compatible: ClassVar[Literal[True]]
8+
PATTERN: ClassVar[str]
9+
def transform(self, node, results): ...

stdlib/lib2to3/fixes/fix_getcwdu.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
class FixGetcwdu(fixer_base.BaseFix):
7+
BM_compatible: ClassVar[Literal[True]]
8+
PATTERN: ClassVar[str]
9+
def transform(self, node, results) -> None: ...

stdlib/lib2to3/fixes/fix_has_key.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
class FixHasKey(fixer_base.BaseFix):
7+
BM_compatible: ClassVar[Literal[True]]
8+
PATTERN: ClassVar[str]
9+
def transform(self, node, results): ...

stdlib/lib2to3/fixes/fix_idioms.pyi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
CMP: str
7+
TYPE: str
8+
9+
class FixIdioms(fixer_base.BaseFix):
10+
BM_compatible: ClassVar[Literal[False]]
11+
PATTERN: ClassVar[str]
12+
def match(self, node): ...
13+
def transform(self, node, results): ...
14+
def transform_isinstance(self, node, results): ...
15+
def transform_while(self, node, results) -> None: ...
16+
def transform_sort(self, node, results) -> None: ...

stdlib/lib2to3/fixes/fix_import.pyi

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from _typeshed import StrPath
2+
from collections.abc import Generator
3+
from typing import ClassVar
4+
from typing_extensions import Literal
5+
6+
from .. import fixer_base
7+
from ..pytree import Node
8+
9+
def traverse_imports(names) -> Generator[str, None, None]: ...
10+
11+
class FixImport(fixer_base.BaseFix):
12+
BM_compatible: ClassVar[Literal[True]]
13+
PATTERN: ClassVar[str]
14+
skip: bool
15+
def start_tree(self, tree: Node, name: StrPath) -> None: ...
16+
def transform(self, node, results): ...
17+
def probably_a_local_import(self, imp_name): ...

stdlib/lib2to3/fixes/fix_imports.pyi

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from _typeshed import StrPath
2+
from collections.abc import Generator
3+
from typing import ClassVar
4+
from typing_extensions import Literal
5+
6+
from .. import fixer_base
7+
from ..pytree import Node
8+
9+
MAPPING: dict[str, str]
10+
11+
def alternates(members): ...
12+
def build_pattern(mapping=...) -> Generator[str, None, None]: ...
13+
14+
class FixImports(fixer_base.BaseFix):
15+
BM_compatible: ClassVar[Literal[True]]
16+
mapping = MAPPING # noqa: F821
17+
def build_pattern(self): ...
18+
def compile_pattern(self) -> None: ...
19+
def match(self, node): ...
20+
replace: dict[str, str]
21+
def start_tree(self, tree: Node, filename: StrPath) -> None: ...
22+
def transform(self, node, results) -> None: ...

stdlib/lib2to3/fixes/fix_imports2.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from . import fix_imports
2+
3+
MAPPING: dict[str, str]
4+
5+
class FixImports2(fix_imports.FixImports):
6+
mapping = MAPPING # noqa: F821

stdlib/lib2to3/fixes/fix_input.pyi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from _typeshed import Incomplete
2+
from typing import ClassVar
3+
from typing_extensions import Literal
4+
5+
from .. import fixer_base
6+
7+
context: Incomplete
8+
9+
class FixInput(fixer_base.BaseFix):
10+
BM_compatible: ClassVar[Literal[True]]
11+
PATTERN: ClassVar[str]
12+
def transform(self, node, results): ...

stdlib/lib2to3/fixes/fix_intern.pyi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
class FixIntern(fixer_base.BaseFix):
7+
BM_compatible: ClassVar[Literal[True]]
8+
order: ClassVar[Literal["pre"]]
9+
PATTERN: ClassVar[str]
10+
def transform(self, node, results): ...
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
class FixIsinstance(fixer_base.BaseFix):
7+
BM_compatible: ClassVar[Literal[True]]
8+
PATTERN: ClassVar[str]
9+
def transform(self, node, results) -> None: ...
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
class FixItertools(fixer_base.BaseFix):
7+
BM_compatible: ClassVar[Literal[True]]
8+
it_funcs: str
9+
PATTERN: ClassVar[str]
10+
def transform(self, node, results) -> None: ...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from lib2to3 import fixer_base
2+
from typing import ClassVar
3+
from typing_extensions import Literal
4+
5+
class FixItertoolsImports(fixer_base.BaseFix):
6+
BM_compatible: ClassVar[Literal[True]]
7+
PATTERN: ClassVar[str]
8+
def transform(self, node, results): ...

stdlib/lib2to3/fixes/fix_long.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from lib2to3 import fixer_base
2+
from typing import ClassVar
3+
from typing_extensions import Literal
4+
5+
class FixLong(fixer_base.BaseFix):
6+
BM_compatible: ClassVar[Literal[True]]
7+
PATTERN: ClassVar[Literal["'long'"]]
8+
def transform(self, node, results) -> None: ...

stdlib/lib2to3/fixes/fix_map.pyi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import ClassVar
2+
from typing_extensions import Literal
3+
4+
from .. import fixer_base
5+
6+
class FixMap(fixer_base.ConditionalFix):
7+
BM_compatible: ClassVar[Literal[True]]
8+
PATTERN: ClassVar[str]
9+
skip_on: ClassVar[Literal["future_builtins.map"]]
10+
def transform(self, node, results): ...

0 commit comments

Comments
 (0)