From 27cad856f880c163c5bd116fa76961df5e8ae655 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 10 May 2024 04:50:07 +0200 Subject: [PATCH] Add flake8 (#11676) --- pyrightconfig.stricter.json | 1 + stubs/flake8/@tests/stubtest_allowlist.txt | 4 ++ stubs/flake8/METADATA.toml | 3 + stubs/flake8/flake8/__init__.pyi | 8 +++ stubs/flake8/flake8/_compat.pyi | 5 ++ stubs/flake8/flake8/api/__init__.pyi | 0 stubs/flake8/flake8/api/legacy.pyi | 27 +++++++ stubs/flake8/flake8/checker.pyi | 56 +++++++++++++++ stubs/flake8/flake8/defaults.pyi | 12 ++++ stubs/flake8/flake8/discover_files.pyi | 8 +++ stubs/flake8/flake8/exceptions.pyi | 24 +++++++ stubs/flake8/flake8/formatting/__init__.pyi | 0 .../flake8/formatting/_windows_color.pyi | 1 + stubs/flake8/flake8/formatting/base.pyi | 24 +++++++ stubs/flake8/flake8/formatting/default.pyi | 29 ++++++++ stubs/flake8/flake8/main/__init__.pyi | 0 stubs/flake8/flake8/main/application.pyi | 29 ++++++++ stubs/flake8/flake8/main/cli.pyi | 3 + stubs/flake8/flake8/main/debug.pyi | 5 ++ stubs/flake8/flake8/main/options.pyi | 12 ++++ stubs/flake8/flake8/options/__init__.pyi | 0 stubs/flake8/flake8/options/aggregator.pyi | 12 ++++ stubs/flake8/flake8/options/config.pyi | 10 +++ stubs/flake8/flake8/options/manager.pyi | 71 ++++++++++++++++++ stubs/flake8/flake8/options/parse_args.pyi | 6 ++ stubs/flake8/flake8/plugins/__init__.pyi | 0 stubs/flake8/flake8/plugins/finder.pyi | 48 +++++++++++++ stubs/flake8/flake8/plugins/pycodestyle.pyi | 32 +++++++++ stubs/flake8/flake8/plugins/pyflakes.pyi | 21 ++++++ stubs/flake8/flake8/plugins/reporter.pyi | 9 +++ stubs/flake8/flake8/processor.pyi | 72 +++++++++++++++++++ stubs/flake8/flake8/statistics.pyi | 28 ++++++++ stubs/flake8/flake8/style_guide.pyi | 70 ++++++++++++++++++ stubs/flake8/flake8/utils.pyi | 25 +++++++ stubs/flake8/flake8/violation.pyi | 13 ++++ 35 files changed, 668 insertions(+) create mode 100644 stubs/flake8/@tests/stubtest_allowlist.txt create mode 100644 stubs/flake8/METADATA.toml create mode 100644 stubs/flake8/flake8/__init__.pyi create mode 100644 stubs/flake8/flake8/_compat.pyi create mode 100644 stubs/flake8/flake8/api/__init__.pyi create mode 100644 stubs/flake8/flake8/api/legacy.pyi create mode 100644 stubs/flake8/flake8/checker.pyi create mode 100644 stubs/flake8/flake8/defaults.pyi create mode 100644 stubs/flake8/flake8/discover_files.pyi create mode 100644 stubs/flake8/flake8/exceptions.pyi create mode 100644 stubs/flake8/flake8/formatting/__init__.pyi create mode 100644 stubs/flake8/flake8/formatting/_windows_color.pyi create mode 100644 stubs/flake8/flake8/formatting/base.pyi create mode 100644 stubs/flake8/flake8/formatting/default.pyi create mode 100644 stubs/flake8/flake8/main/__init__.pyi create mode 100644 stubs/flake8/flake8/main/application.pyi create mode 100644 stubs/flake8/flake8/main/cli.pyi create mode 100644 stubs/flake8/flake8/main/debug.pyi create mode 100644 stubs/flake8/flake8/main/options.pyi create mode 100644 stubs/flake8/flake8/options/__init__.pyi create mode 100644 stubs/flake8/flake8/options/aggregator.pyi create mode 100644 stubs/flake8/flake8/options/config.pyi create mode 100644 stubs/flake8/flake8/options/manager.pyi create mode 100644 stubs/flake8/flake8/options/parse_args.pyi create mode 100644 stubs/flake8/flake8/plugins/__init__.pyi create mode 100644 stubs/flake8/flake8/plugins/finder.pyi create mode 100644 stubs/flake8/flake8/plugins/pycodestyle.pyi create mode 100644 stubs/flake8/flake8/plugins/pyflakes.pyi create mode 100644 stubs/flake8/flake8/plugins/reporter.pyi create mode 100644 stubs/flake8/flake8/processor.pyi create mode 100644 stubs/flake8/flake8/statistics.pyi create mode 100644 stubs/flake8/flake8/style_guide.pyi create mode 100644 stubs/flake8/flake8/utils.pyi create mode 100644 stubs/flake8/flake8/violation.pyi diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index cac67e234..f29f1f094 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -44,6 +44,7 @@ "stubs/defusedxml", "stubs/docker", "stubs/docutils", + "stubs/flake8", "stubs/Flask-SocketIO", "stubs/fpdf2", "stubs/google-cloud-ndb", diff --git a/stubs/flake8/@tests/stubtest_allowlist.txt b/stubs/flake8/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000..c65acf1ff --- /dev/null +++ b/stubs/flake8/@tests/stubtest_allowlist.txt @@ -0,0 +1,4 @@ +flake8.__main__ + +# Can't reconcile @cached_property with @property. +flake8.processor.FileProcessor.file_tokens diff --git a/stubs/flake8/METADATA.toml b/stubs/flake8/METADATA.toml new file mode 100644 index 000000000..36c0facd5 --- /dev/null +++ b/stubs/flake8/METADATA.toml @@ -0,0 +1,3 @@ +version = "7.0.*" +upstream_repository = "https://github.com/pycqa/flake8" +requires = ["types-pyflakes"] diff --git a/stubs/flake8/flake8/__init__.pyi b/stubs/flake8/flake8/__init__.pyi new file mode 100644 index 000000000..56cd4da6b --- /dev/null +++ b/stubs/flake8/flake8/__init__.pyi @@ -0,0 +1,8 @@ +from logging import Logger + +LOG: Logger +__version__: str +__version_info__: tuple[int, int, int] +LOG_FORMAT: str + +def configure_logging(verbosity: int, filename: str | None = None, logformat: str = ...) -> None: ... diff --git a/stubs/flake8/flake8/_compat.pyi b/stubs/flake8/flake8/_compat.pyi new file mode 100644 index 000000000..2cf456fec --- /dev/null +++ b/stubs/flake8/flake8/_compat.pyi @@ -0,0 +1,5 @@ +from typing import Final + +FSTRING_START: Final[int] +FSTRING_MIDDLE: Final[int] +FSTRING_END: Final[int] diff --git a/stubs/flake8/flake8/api/__init__.pyi b/stubs/flake8/flake8/api/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/stubs/flake8/flake8/api/legacy.pyi b/stubs/flake8/flake8/api/legacy.pyi new file mode 100644 index 000000000..7f8ad95d2 --- /dev/null +++ b/stubs/flake8/flake8/api/legacy.pyi @@ -0,0 +1,27 @@ +import argparse +from _typeshed import Unused +from typing import Any + +from ..formatting import base as formatter +from ..main import application as app + +__all__ = ("get_style_guide",) + +class Report: + def __init__(self, application: app.Application) -> None: ... + @property + def total_errors(self) -> int: ... + def get_statistics(self, violation: str) -> list[str]: ... + +class StyleGuide: + def __init__(self, application: app.Application) -> None: ... + @property + def options(self) -> argparse.Namespace: ... + @property + def paths(self) -> list[str]: ... + def check_files(self, paths: list[str] | None = None) -> Report: ... + def excluded(self, filename: str, parent: str | None = None) -> bool: ... + def init_report(self, reporter: type[formatter.BaseFormatter] | None = None) -> None: ... + def input_file(self, filename: str, lines: Unused = None, expected: Unused = None, line_offset: Unused = 0) -> Report: ... + +def get_style_guide(**kwargs: Any) -> StyleGuide: ... diff --git a/stubs/flake8/flake8/checker.pyi b/stubs/flake8/flake8/checker.pyi new file mode 100644 index 000000000..a2e67f9c0 --- /dev/null +++ b/stubs/flake8/flake8/checker.pyi @@ -0,0 +1,56 @@ +import argparse +import tokenize +from _typeshed import Incomplete +from collections.abc import Sequence +from logging import Logger +from typing import Any +from typing_extensions import TypeAlias + +from .plugins.finder import Checkers, LoadedPlugin +from .processor import _LogicalMapping +from .style_guide import StyleGuideManager + +Results: TypeAlias = list[tuple[str, int, int, str, str | None]] + +LOG: Logger +SERIAL_RETRY_ERRNOS: Incomplete + +class Manager: + style_guide: Incomplete + options: Incomplete + plugins: Incomplete + jobs: Incomplete + statistics: Incomplete + exclude: Incomplete + argv: Incomplete + results: Incomplete + def __init__(self, style_guide: StyleGuideManager, plugins: Checkers, argv: Sequence[str]) -> None: ... + def report(self) -> tuple[int, int]: ... + def run_parallel(self) -> None: ... + def run_serial(self) -> None: ... + def run(self) -> None: ... + filenames: Incomplete + def start(self) -> None: ... + def stop(self) -> None: ... + +class FileChecker: + options: Incomplete + filename: Incomplete + plugins: Incomplete + results: Incomplete + statistics: Incomplete + processor: Incomplete + display_name: Incomplete + should_process: bool + def __init__(self, *, filename: str, plugins: Checkers, options: argparse.Namespace) -> None: ... + def report(self, error_code: str | None, line_number: int, column: int, text: str) -> str: ... + def run_check(self, plugin: LoadedPlugin, **arguments: Any) -> Any: ... + def run_ast_checks(self) -> None: ... + def run_logical_checks(self) -> None: ... + def run_physical_checks(self, physical_line: str) -> None: ... + def process_tokens(self) -> None: ... + def run_checks(self) -> tuple[str, Results, dict[str, int]]: ... + def handle_newline(self, token_type: int) -> None: ... + def check_physical_eol(self, token: tokenize.TokenInfo, prev_physical: str) -> None: ... + +def find_offset(offset: int, mapping: _LogicalMapping) -> tuple[int, int]: ... diff --git a/stubs/flake8/flake8/defaults.pyi b/stubs/flake8/flake8/defaults.pyi new file mode 100644 index 000000000..1a9459d17 --- /dev/null +++ b/stubs/flake8/flake8/defaults.pyi @@ -0,0 +1,12 @@ +from re import Pattern +from typing import Final + +EXCLUDE: Final[tuple[str, ...]] +IGNORE: Final[tuple[str, ...]] +MAX_LINE_LENGTH: Final = 79 +INDENT_SIZE: Final = 4 +WHITESPACE: Final[frozenset[str]] +STATISTIC_NAMES: Final[tuple[str, ...]] +NOQA_INLINE_REGEXP: Final[Pattern[str]] +NOQA_FILE: Final[Pattern[str]] +VALID_CODE_PREFIX: Final[Pattern[str]] diff --git a/stubs/flake8/flake8/discover_files.pyi b/stubs/flake8/flake8/discover_files.pyi new file mode 100644 index 000000000..d00b1f347 --- /dev/null +++ b/stubs/flake8/flake8/discover_files.pyi @@ -0,0 +1,8 @@ +from collections.abc import Generator, Sequence +from logging import Logger + +LOG: Logger + +def expand_paths( + *, paths: Sequence[str], stdin_display_name: str, filename_patterns: Sequence[str], exclude: Sequence[str] +) -> Generator[str, None, None]: ... diff --git a/stubs/flake8/flake8/exceptions.pyi b/stubs/flake8/flake8/exceptions.pyi new file mode 100644 index 000000000..7c6e3fc70 --- /dev/null +++ b/stubs/flake8/flake8/exceptions.pyi @@ -0,0 +1,24 @@ +from _typeshed import Incomplete + +class Flake8Exception(Exception): ... +class EarlyQuit(Flake8Exception): ... +class ExecutionError(Flake8Exception): ... + +class FailedToLoadPlugin(Flake8Exception): + FORMAT: str + plugin_name: Incomplete + original_exception: Incomplete + def __init__(self, plugin_name: str, exception: Exception) -> None: ... + +class PluginRequestedUnknownParameters(Flake8Exception): + FORMAT: str + plugin_name: Incomplete + original_exception: Incomplete + def __init__(self, plugin_name: str, exception: Exception) -> None: ... + +class PluginExecutionFailed(Flake8Exception): + FORMAT: str + filename: Incomplete + plugin_name: Incomplete + original_exception: Incomplete + def __init__(self, filename: str, plugin_name: str, exception: Exception) -> None: ... diff --git a/stubs/flake8/flake8/formatting/__init__.pyi b/stubs/flake8/flake8/formatting/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/stubs/flake8/flake8/formatting/_windows_color.pyi b/stubs/flake8/flake8/formatting/_windows_color.pyi new file mode 100644 index 000000000..f8af8baa7 --- /dev/null +++ b/stubs/flake8/flake8/formatting/_windows_color.pyi @@ -0,0 +1 @@ +terminal_supports_color: bool diff --git a/stubs/flake8/flake8/formatting/base.pyi b/stubs/flake8/flake8/formatting/base.pyi new file mode 100644 index 000000000..2ed0775ba --- /dev/null +++ b/stubs/flake8/flake8/formatting/base.pyi @@ -0,0 +1,24 @@ +import argparse +from _typeshed import Incomplete + +from ..statistics import Statistics +from ..violation import Violation as Violation + +class BaseFormatter: + options: Incomplete + filename: Incomplete + output_fd: Incomplete + newline: str + color: Incomplete + def __init__(self, options: argparse.Namespace) -> None: ... + def after_init(self) -> None: ... + def beginning(self, filename: str) -> None: ... + def finished(self, filename: str) -> None: ... + def start(self) -> None: ... + def handle(self, error: Violation) -> None: ... + def format(self, error: Violation) -> str | None: ... + def show_statistics(self, statistics: Statistics) -> None: ... + def show_benchmarks(self, benchmarks: list[tuple[str, float]]) -> None: ... + def show_source(self, error: Violation) -> str | None: ... + def write(self, line: str | None, source: str | None) -> None: ... + def stop(self) -> None: ... diff --git a/stubs/flake8/flake8/formatting/default.pyi b/stubs/flake8/flake8/formatting/default.pyi new file mode 100644 index 000000000..a2cdebdd3 --- /dev/null +++ b/stubs/flake8/flake8/formatting/default.pyi @@ -0,0 +1,29 @@ +from _typeshed import Incomplete + +from ..violation import Violation +from .base import BaseFormatter + +COLORS: dict[str, str] +COLORS_OFF: dict[str, str] + +class SimpleFormatter(BaseFormatter): + error_format: str + def format(self, error: Violation) -> str | None: ... + +class Default(SimpleFormatter): + error_format: str + def after_init(self) -> None: ... + +class Pylint(SimpleFormatter): + error_format: str + +class FilenameOnly(SimpleFormatter): + error_format: str + filenames_already_printed: Incomplete + def after_init(self) -> None: ... + def show_source(self, error: Violation) -> str | None: ... + def format(self, error: Violation) -> str | None: ... + +class Nothing(BaseFormatter): + def format(self, error: Violation) -> str | None: ... + def show_source(self, error: Violation) -> str | None: ... diff --git a/stubs/flake8/flake8/main/__init__.pyi b/stubs/flake8/flake8/main/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/stubs/flake8/flake8/main/application.pyi b/stubs/flake8/flake8/main/application.pyi new file mode 100644 index 000000000..b41ba83c8 --- /dev/null +++ b/stubs/flake8/flake8/main/application.pyi @@ -0,0 +1,29 @@ +from _typeshed import Incomplete +from collections.abc import Sequence +from logging import Logger + +LOG: Logger + +class Application: + start_time: Incomplete + end_time: Incomplete + plugins: Incomplete + formatter: Incomplete + guide: Incomplete + file_checker_manager: Incomplete + options: Incomplete + result_count: int + total_result_count: int + catastrophic_failure: bool + def __init__(self) -> None: ... + def exit_code(self) -> int: ... + def make_formatter(self) -> None: ... + def make_guide(self) -> None: ... + def make_file_checker_manager(self, argv: Sequence[str]) -> None: ... + def run_checks(self) -> None: ... + def report_benchmarks(self) -> None: ... + def report_errors(self) -> None: ... + def report_statistics(self) -> None: ... + def initialize(self, argv: Sequence[str]) -> None: ... + def report(self) -> None: ... + def run(self, argv: Sequence[str]) -> None: ... diff --git a/stubs/flake8/flake8/main/cli.pyi b/stubs/flake8/flake8/main/cli.pyi new file mode 100644 index 000000000..2d91d1aa3 --- /dev/null +++ b/stubs/flake8/flake8/main/cli.pyi @@ -0,0 +1,3 @@ +from collections.abc import Sequence + +def main(argv: Sequence[str] | None = None) -> int: ... diff --git a/stubs/flake8/flake8/main/debug.pyi b/stubs/flake8/flake8/main/debug.pyi new file mode 100644 index 000000000..2f1ef97cf --- /dev/null +++ b/stubs/flake8/flake8/main/debug.pyi @@ -0,0 +1,5 @@ +from typing import Any + +from ..plugins.finder import Plugins + +def information(version: str, plugins: Plugins) -> dict[str, Any]: ... diff --git a/stubs/flake8/flake8/main/options.pyi b/stubs/flake8/flake8/main/options.pyi new file mode 100644 index 000000000..1f9bf70a5 --- /dev/null +++ b/stubs/flake8/flake8/main/options.pyi @@ -0,0 +1,12 @@ +from argparse import ArgumentParser + +from ..options.manager import OptionManager + +def stage1_arg_parser() -> ArgumentParser: ... + +class JobsArgument: + is_auto: bool + n_jobs: int + def __init__(self, arg: str) -> None: ... + +def register_default_options(option_manager: OptionManager) -> None: ... diff --git a/stubs/flake8/flake8/options/__init__.pyi b/stubs/flake8/flake8/options/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/stubs/flake8/flake8/options/aggregator.pyi b/stubs/flake8/flake8/options/aggregator.pyi new file mode 100644 index 000000000..a6bb859a8 --- /dev/null +++ b/stubs/flake8/flake8/options/aggregator.pyi @@ -0,0 +1,12 @@ +import argparse +import configparser +from collections.abc import Sequence +from logging import Logger + +from .manager import OptionManager + +LOG: Logger + +def aggregate_options( + manager: OptionManager, cfg: configparser.RawConfigParser, cfg_dir: str, argv: Sequence[str] | None +) -> argparse.Namespace: ... diff --git a/stubs/flake8/flake8/options/config.pyi b/stubs/flake8/flake8/options/config.pyi new file mode 100644 index 000000000..a443261b1 --- /dev/null +++ b/stubs/flake8/flake8/options/config.pyi @@ -0,0 +1,10 @@ +import configparser +from logging import Logger +from typing import Any + +from .manager import OptionManager + +LOG: Logger + +def load_config(config: str | None, extra: list[str], *, isolated: bool = False) -> tuple[configparser.RawConfigParser, str]: ... +def parse_config(option_manager: OptionManager, cfg: configparser.RawConfigParser, cfg_dir: str) -> dict[str, Any]: ... diff --git a/stubs/flake8/flake8/options/manager.pyi b/stubs/flake8/flake8/options/manager.pyi new file mode 100644 index 000000000..22196c0e0 --- /dev/null +++ b/stubs/flake8/flake8/options/manager.pyi @@ -0,0 +1,71 @@ +import argparse +from _typeshed import Incomplete +from collections.abc import Callable, Sequence +from enum import Enum +from logging import Logger +from typing import Any, Final + +from ..plugins.finder import Plugins + +LOG: Logger + +class _ARG(Enum): + NO: Final = 1 + +class Option: + short_option_name: Incomplete + long_option_name: Incomplete + option_args: Incomplete + action: Incomplete + default: Incomplete + type: Incomplete + dest: Incomplete + nargs: Incomplete + const: Incomplete + choices: Incomplete + help: Incomplete + metavar: Incomplete + required: Incomplete + option_kwargs: Incomplete + parse_from_config: Incomplete + comma_separated_list: Incomplete + normalize_paths: Incomplete + config_name: Incomplete + def __init__( + self, + short_option_name: str | _ARG = ..., + long_option_name: str | _ARG = ..., + action: str | type[argparse.Action] | _ARG = ..., + default: Any | _ARG = ..., + type: Callable[..., Any] | _ARG = ..., + dest: str | _ARG = ..., + nargs: int | str | _ARG = ..., + const: Any | _ARG = ..., + choices: Sequence[Any] | _ARG = ..., + help: str | _ARG = ..., + metavar: str | _ARG = ..., + required: bool | _ARG = ..., + parse_from_config: bool = False, + comma_separated_list: bool = False, + normalize_paths: bool = False, + ) -> None: ... + @property + def filtered_option_kwargs(self) -> dict[str, Any]: ... + def normalize(self, value: Any, *normalize_args: str) -> Any: ... + def to_argparse(self) -> tuple[list[str], dict[str, Any]]: ... + +class OptionManager: + formatter_names: Incomplete + parser: Incomplete + config_options_dict: Incomplete + options: Incomplete + extended_default_ignore: Incomplete + extended_default_select: Incomplete + def __init__( + self, *, version: str, plugin_versions: str, parents: list[argparse.ArgumentParser], formatter_names: list[str] + ) -> None: ... + def register_plugins(self, plugins: Plugins) -> None: ... + def add_option(self, *args: Any, **kwargs: Any) -> None: ... + def extend_default_ignore(self, error_codes: Sequence[str]) -> None: ... + def extend_default_select(self, error_codes: Sequence[str]) -> None: ... + def parse_args(self, args: Sequence[str] | None = None, values: argparse.Namespace | None = None) -> argparse.Namespace: ... diff --git a/stubs/flake8/flake8/options/parse_args.pyi b/stubs/flake8/flake8/options/parse_args.pyi new file mode 100644 index 000000000..2818b87ce --- /dev/null +++ b/stubs/flake8/flake8/options/parse_args.pyi @@ -0,0 +1,6 @@ +import argparse +from collections.abc import Sequence + +from ..plugins import finder + +def parse_args(argv: Sequence[str]) -> tuple[finder.Plugins, argparse.Namespace]: ... diff --git a/stubs/flake8/flake8/plugins/__init__.pyi b/stubs/flake8/flake8/plugins/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/stubs/flake8/flake8/plugins/finder.pyi b/stubs/flake8/flake8/plugins/finder.pyi new file mode 100644 index 000000000..0f1949fa6 --- /dev/null +++ b/stubs/flake8/flake8/plugins/finder.pyi @@ -0,0 +1,48 @@ +import configparser +import importlib.metadata +from collections.abc import Generator +from logging import Logger +from typing import Any, Final, NamedTuple + +LOG: Logger +FLAKE8_GROUPS: Final[frozenset[str]] +BANNED_PLUGINS: dict[str, str] + +class Plugin(NamedTuple): + package: str + version: str + entry_point: importlib.metadata.EntryPoint + +class LoadedPlugin(NamedTuple): + plugin: Plugin + obj: Any + parameters: dict[str, bool] + @property + def entry_name(self) -> str: ... + @property + def display_name(self) -> str: ... + +class Checkers(NamedTuple): + tree: list[LoadedPlugin] + logical_line: list[LoadedPlugin] + physical_line: list[LoadedPlugin] + +class Plugins(NamedTuple): + checkers: Checkers + reporters: dict[str, LoadedPlugin] + disabled: list[LoadedPlugin] + def all_plugins(self) -> Generator[LoadedPlugin, None, None]: ... + def versions_str(self) -> str: ... + +class PluginOptions(NamedTuple): + local_plugin_paths: tuple[str, ...] + enable_extensions: frozenset[str] + require_plugins: frozenset[str] + @classmethod + def blank(cls) -> PluginOptions: ... + +def parse_plugin_options( + cfg: configparser.RawConfigParser, cfg_dir: str, *, enable_extensions: str | None, require_plugins: str | None +) -> PluginOptions: ... +def find_plugins(cfg: configparser.RawConfigParser, opts: PluginOptions) -> list[Plugin]: ... +def load_plugins(plugins: list[Plugin], opts: PluginOptions) -> Plugins: ... diff --git a/stubs/flake8/flake8/plugins/pycodestyle.pyi b/stubs/flake8/flake8/plugins/pycodestyle.pyi new file mode 100644 index 000000000..2a4194f96 --- /dev/null +++ b/stubs/flake8/flake8/plugins/pycodestyle.pyi @@ -0,0 +1,32 @@ +from collections.abc import Generator +from typing import Any + +def pycodestyle_logical( + blank_before: Any, + blank_lines: Any, + checker_state: Any, + hang_closing: Any, + indent_char: Any, + indent_level: Any, + indent_size: Any, + line_number: Any, + lines: Any, + logical_line: Any, + max_doc_length: Any, + noqa: Any, + previous_indent_level: Any, + previous_logical: Any, + previous_unindented_logical_line: Any, + tokens: Any, + verbose: Any, +) -> Generator[tuple[int, str], None, None]: ... +def pycodestyle_physical( + indent_char: Any, + line_number: Any, + lines: Any, + max_line_length: Any, + multiline: Any, + noqa: Any, + physical_line: Any, + total_lines: Any, +) -> Generator[tuple[int, str], None, None]: ... diff --git a/stubs/flake8/flake8/plugins/pyflakes.pyi b/stubs/flake8/flake8/plugins/pyflakes.pyi new file mode 100644 index 000000000..3acc52ece --- /dev/null +++ b/stubs/flake8/flake8/plugins/pyflakes.pyi @@ -0,0 +1,21 @@ +from argparse import Namespace +from ast import AST +from collections.abc import Generator +from logging import Logger +from typing import Any + +from pyflakes.checker import Checker + +from ..options.manager import OptionManager + +LOG: Logger +FLAKE8_PYFLAKES_CODES: dict[str, str] + +class FlakesChecker(Checker): + with_doctest: bool + def __init__(self, tree: AST, filename: str) -> None: ... + @classmethod + def add_options(cls, parser: OptionManager) -> None: ... + @classmethod + def parse_options(cls, options: Namespace) -> None: ... + def run(self) -> Generator[tuple[int, int, str, type[Any]], None, None]: ... diff --git a/stubs/flake8/flake8/plugins/reporter.pyi b/stubs/flake8/flake8/plugins/reporter.pyi new file mode 100644 index 000000000..ee3e72711 --- /dev/null +++ b/stubs/flake8/flake8/plugins/reporter.pyi @@ -0,0 +1,9 @@ +import argparse +from logging import Logger + +from ..formatting.base import BaseFormatter +from .finder import LoadedPlugin + +LOG: Logger + +def make(reporters: dict[str, LoadedPlugin], options: argparse.Namespace) -> BaseFormatter: ... diff --git a/stubs/flake8/flake8/processor.pyi b/stubs/flake8/flake8/processor.pyi new file mode 100644 index 000000000..87d26df68 --- /dev/null +++ b/stubs/flake8/flake8/processor.pyi @@ -0,0 +1,72 @@ +from _typeshed import Incomplete +from argparse import Namespace +from ast import AST +from collections.abc import Generator +from logging import Logger +from tokenize import TokenInfo +from typing import Any, Final +from typing_extensions import TypeAlias + +from .plugins.finder import LoadedPlugin + +LOG: Logger +NEWLINE: Final[frozenset[int]] +SKIP_TOKENS: Final[frozenset[int]] + +_LogicalMapping: TypeAlias = list[tuple[int, tuple[int, int]]] +_Logical: TypeAlias = tuple[list[str], list[str], _LogicalMapping] + +class FileProcessor: + noqa: bool + options: Incomplete + filename: Incomplete + lines: Incomplete + blank_before: int + blank_lines: int + checker_state: Incomplete + hang_closing: Incomplete + indent_char: Incomplete + indent_level: int + indent_size: Incomplete + line_number: int + logical_line: str + max_line_length: Incomplete + max_doc_length: Incomplete + multiline: bool + previous_indent_level: int + previous_logical: str + previous_unindented_logical_line: str + tokens: Incomplete + total_lines: Incomplete + verbose: Incomplete + statistics: Incomplete + def __init__(self, filename: str, options: Namespace, lines: list[str] | None = None) -> None: ... + @property + def file_tokens(self) -> list[TokenInfo]: ... + def fstring_start(self, lineno: int) -> None: ... + def multiline_string(self, token: TokenInfo) -> Generator[str, None, None]: ... + def reset_blank_before(self) -> None: ... + def delete_first_token(self) -> None: ... + def visited_new_blank_line(self) -> None: ... + def update_state(self, mapping: _LogicalMapping) -> None: ... + def update_checker_state_for(self, plugin: LoadedPlugin) -> None: ... + def next_logical_line(self) -> None: ... + def build_logical_line_tokens(self) -> _Logical: ... + def build_ast(self) -> AST: ... + def build_logical_line(self) -> tuple[str, str, _LogicalMapping]: ... + def keyword_arguments_for(self, parameters: dict[str, bool], arguments: dict[str, Any]) -> dict[str, Any]: ... + def generate_tokens(self) -> Generator[TokenInfo, None, None]: ... + def noqa_line_for(self, line_number: int) -> str | None: ... + def next_line(self) -> str: ... + def read_lines(self) -> list[str]: ... + def read_lines_from_filename(self) -> list[str]: ... + def read_lines_from_stdin(self) -> list[str]: ... + def should_ignore_file(self) -> bool: ... + def strip_utf_bom(self) -> None: ... + +def is_eol_token(token: TokenInfo) -> bool: ... +def is_multiline_string(token: TokenInfo) -> bool: ... +def token_is_newline(token: TokenInfo) -> bool: ... +def count_parentheses(current_parentheses_count: int, token_text: str) -> int: ... +def expand_indent(line: str) -> int: ... +def mutate_string(text: str) -> str: ... diff --git a/stubs/flake8/flake8/statistics.pyi b/stubs/flake8/flake8/statistics.pyi new file mode 100644 index 000000000..d550ebc91 --- /dev/null +++ b/stubs/flake8/flake8/statistics.pyi @@ -0,0 +1,28 @@ +from _typeshed import Incomplete +from collections.abc import Generator +from typing import NamedTuple + +from .violation import Violation + +class Statistics: + def __init__(self) -> None: ... + def error_codes(self) -> list[str]: ... + def record(self, error: Violation) -> None: ... + def statistics_for(self, prefix: str, filename: str | None = None) -> Generator[Statistic, None, None]: ... + +class Key(NamedTuple): + filename: str + code: str + @classmethod + def create_from(cls, error: Violation) -> Key: ... + def matches(self, prefix: str, filename: str | None) -> bool: ... + +class Statistic: + error_code: Incomplete + filename: Incomplete + message: Incomplete + count: Incomplete + def __init__(self, error_code: str, filename: str, message: str, count: int) -> None: ... + @classmethod + def create_from(cls, error: Violation) -> Statistic: ... + def increment(self) -> None: ... diff --git a/stubs/flake8/flake8/style_guide.pyi b/stubs/flake8/flake8/style_guide.pyi new file mode 100644 index 000000000..770a85576 --- /dev/null +++ b/stubs/flake8/flake8/style_guide.pyi @@ -0,0 +1,70 @@ +import argparse +import enum +from _typeshed import Incomplete +from collections.abc import Generator, Sequence + +from .formatting.base import BaseFormatter +from .statistics import Statistics + +__all__ = ("StyleGuide",) + +class Selected(enum.Enum): + Explicitly: str + Implicitly: str + +class Ignored(enum.Enum): + Explicitly: str + Implicitly: str + +class Decision(enum.Enum): + Ignored: str + Selected: str + +class DecisionEngine: + cache: Incomplete + selected_explicitly: Incomplete + ignored_explicitly: Incomplete + selected: Incomplete + ignored: Incomplete + def __init__(self, options: argparse.Namespace) -> None: ... + def was_selected(self, code: str) -> Selected | Ignored: ... + def was_ignored(self, code: str) -> Selected | Ignored: ... + def make_decision(self, code: str) -> Decision: ... + def decision_for(self, code: str) -> Decision: ... + +class StyleGuideManager: + options: Incomplete + formatter: Incomplete + stats: Incomplete + decider: Incomplete + style_guides: Incomplete + default_style_guide: Incomplete + style_guide_for: Incomplete + def __init__(self, options: argparse.Namespace, formatter: BaseFormatter, decider: DecisionEngine | None = None) -> None: ... + def populate_style_guides_with(self, options: argparse.Namespace) -> Generator[StyleGuide, None, None]: ... + def processing_file(self, filename: str) -> Generator[StyleGuide, None, None]: ... + def handle_error( + self, code: str, filename: str, line_number: int, column_number: int, text: str, physical_line: str | None = None + ) -> int: ... + +class StyleGuide: + options: Incomplete + formatter: Incomplete + stats: Incomplete + decider: Incomplete + filename: Incomplete + def __init__( + self, + options: argparse.Namespace, + formatter: BaseFormatter, + stats: Statistics, + filename: str | None = None, + decider: DecisionEngine | None = None, + ) -> None: ... + def copy(self, filename: str | None = None, extend_ignore_with: Sequence[str] | None = None) -> StyleGuide: ... + def processing_file(self, filename: str) -> Generator[StyleGuide, None, None]: ... + def applies_to(self, filename: str) -> bool: ... + def should_report_error(self, code: str) -> Decision: ... + def handle_error( + self, code: str, filename: str, line_number: int, column_number: int, text: str, physical_line: str | None = None + ) -> int: ... diff --git a/stubs/flake8/flake8/utils.pyi b/stubs/flake8/flake8/utils.pyi new file mode 100644 index 000000000..b12329404 --- /dev/null +++ b/stubs/flake8/flake8/utils.pyi @@ -0,0 +1,25 @@ +import logging +from collections.abc import Sequence +from re import Pattern +from typing import Final, NamedTuple + +COMMA_SEPARATED_LIST_RE: Final[Pattern[str]] +LOCAL_PLUGIN_LIST_RE: Final[Pattern[str]] +NORMALIZE_PACKAGE_NAME_RE: Final[Pattern[str]] + +def parse_comma_separated_list(value: str, regexp: Pattern[str] = ...) -> list[str]: ... + +class _Token(NamedTuple): + tp: str + src: str + +def parse_files_to_codes_mapping(value_: Sequence[str] | str) -> list[tuple[str, list[str]]]: ... +def normalize_paths(paths: Sequence[str], parent: str = ".") -> list[str]: ... +def normalize_path(path: str, parent: str = ".") -> str: ... +def stdin_get_value() -> str: ... +def stdin_get_lines() -> list[str]: ... +def is_using_stdin(paths: list[str]) -> bool: ... +def fnmatch(filename: str, patterns: Sequence[str]) -> bool: ... +def matches_filename(path: str, patterns: Sequence[str], log_message: str, logger: logging.Logger) -> bool: ... +def get_python_version() -> str: ... +def normalize_pypi_name(s: str) -> str: ... diff --git a/stubs/flake8/flake8/violation.pyi b/stubs/flake8/flake8/violation.pyi new file mode 100644 index 000000000..7526471eb --- /dev/null +++ b/stubs/flake8/flake8/violation.pyi @@ -0,0 +1,13 @@ +from logging import Logger +from typing import NamedTuple + +LOG: Logger + +class Violation(NamedTuple): + code: str + filename: str + line_number: int + column_number: int + text: str + physical_line: str | None + def is_inline_ignored(self, disable_noqa: bool) -> bool: ...