diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index ff204d696..c5bc42cee 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -19,6 +19,7 @@ "stubs/scribe", "stubs/tornado", // Modules that are incomplete in some way. + "stdlib/lib2to3/refactor.pyi", "stdlib/sqlite3/dbapi2.pyi", "stdlib/tkinter", "stdlib/xml/dom", diff --git a/stdlib/distutils/util.pyi b/stdlib/distutils/util.pyi index 0086d726a..9b0915570 100644 --- a/stdlib/distutils/util.pyi +++ b/stdlib/distutils/util.pyi @@ -1,23 +1,45 @@ -from typing import Any, Callable, List, Mapping, Optional, Tuple +from _typeshed import StrPath +from collections.abc import Callable, Container, Iterable, Mapping +from typing import Any, Tuple def get_platform() -> str: ... def convert_path(pathname: str) -> str: ... def change_root(new_root: str, pathname: str) -> str: ... def check_environ() -> None: ... def subst_vars(s: str, local_vars: Mapping[str, str]) -> None: ... -def split_quoted(s: str) -> List[str]: ... +def split_quoted(s: str) -> list[str]: ... def execute( - func: Callable[..., None], args: Tuple[Any, ...], msg: Optional[str] = ..., verbose: bool = ..., dry_run: bool = ... + func: Callable[..., None], args: Tuple[Any, ...], msg: str | None = ..., verbose: bool = ..., dry_run: bool = ... ) -> None: ... def strtobool(val: str) -> bool: ... def byte_compile( - py_files: List[str], + py_files: list[str], optimize: int = ..., force: bool = ..., - prefix: Optional[str] = ..., - base_dir: Optional[str] = ..., + prefix: str | None = ..., + base_dir: str | None = ..., verbose: bool = ..., dry_run: bool = ..., - direct: Optional[bool] = ..., + direct: bool | None = ..., ) -> None: ... def rfc822_escape(header: str) -> str: ... +def run_2to3( + files: Iterable[str], + fixer_names: Iterable[str] | None = ..., + options: Mapping[str, Any] | None = ..., + explicit: Container[str] | None = ..., # unused +) -> None: ... +def copydir_run_2to3( + src: StrPath, + dest: StrPath, + template: str | None = ..., + fixer_names: Iterable[str] | None = ..., + options: Mapping[str, Any] | None = ..., + explicit: Container[str] | None = ..., +) -> list[str]: ... + +class Mixin2to3: + fixer_names: Iterable[str] | None + options: Mapping[str, Any] | None + explicit: Container[str] | None + def run_2to3(self, files: Iterable[str]) -> None: ... diff --git a/stdlib/lib2to3/refactor.pyi b/stdlib/lib2to3/refactor.pyi new file mode 100644 index 000000000..6687092d8 --- /dev/null +++ b/stdlib/lib2to3/refactor.pyi @@ -0,0 +1,70 @@ +from collections.abc import Container, Generator, Iterable, Mapping +from logging import Logger +from typing import Any, ClassVar, NoReturn + +from .pgen2.grammar import Grammar + +_Driver = Any # really lib2to3.driver.Driver +_BottomMatcher = Any # really lib2to3.btm_matcher.BottomMatcher + +def get_all_fix_names(fixer_pkg: str, remove_prefix: bool = ...) -> list[str]: ... +def get_fixers_from_package(pkg_name: str) -> list[str]: ... + +class FixerError(Exception): ... + +class RefactoringTool: + CLASS_PREFIX: ClassVar[str] + FILE_PREFIX: ClassVar[str] + fixers: Iterable[str] + explicit: Container[str] + options: dict[str, Any] + grammar: Grammar + write_unchanged_files: bool + errors: list[Any] + logger: Logger + fixer_log: list[Any] + wrote: bool + driver: _Driver + pre_order: Any + post_order: Any + files: list[Any] + BM: _BottomMatcher + bmi_pre_order: list[Any] + bmi_post_order: list[Any] + def __init__( + self, fixer_names: Iterable[str], options: Mapping[str, Any] | None = ..., explicit: Container[str] | None = ... + ) -> None: ... + def get_fixers(self) -> tuple[list[Any], list[Any]]: ... + def log_error(self, msg: str, *args: Any, **kwds: Any) -> NoReturn: ... + def log_message(self, msg: str, *args: Any) -> None: ... + def log_debug(self, msg: str, *args: Any) -> None: ... + def print_output(self, old_text: str, new_text: str, filename: str, equal): ... + def refactor(self, items: Iterable[str], write: bool = ..., doctests_only: bool = ...) -> None: ... + def refactor_dir(self, dir_name: str, write: bool = ..., doctests_only: bool = ...) -> None: ... + def _read_python_source(self, filename: str) -> tuple[str, str]: ... + def refactor_file(self, filename: str, write: bool = ..., doctests_only: bool = ...) -> None: ... + def refactor_string(self, data: str, name: str): ... + def refactor_stdin(self, doctests_only: bool = ...) -> None: ... + def refactor_tree(self, tree, name: str) -> bool: ... + def traverse_by(self, fixers, traversal) -> None: ... + def processed_file( + self, new_text: str, filename: str, old_text: str | None = ..., write: bool = ..., encoding: str | None = ... + ) -> None: ... + def write_file(self, new_text: str, filename: str, old_text: str, encoding: str | None = ...) -> None: ... + PS1: ClassVar[str] + PS2: ClassVar[str] + def refactor_docstring(self, input: str, filename: str) -> str: ... + def refactor_doctest(self, block: list[str], lineno: int, indent: int, filename: str) -> list[str]: ... + def summarize(self) -> None: ... + def parse_block(self, block: Iterable[str], lineno: int, indent: int): ... + def wrap_toks( + self, block: Iterable[str], lineno: int, indent: int + ) -> Generator[tuple[Any, Any, tuple[int, int], tuple[int, int], str], None, None]: ... + def gen_lines(self, block: Iterable[str], indent: int) -> Generator[str, None, None]: ... + +class MultiprocessingUnsupported(Exception): ... + +class MultiprocessRefactoringTool(RefactoringTool): + queue: Any | None + output_lock: Any | None + def refactor(self, items: Iterable[str], write: bool = ..., doctests_only: bool = ..., num_processes: int = ...) -> None: ...