Add flake8 (#11676)

This commit is contained in:
Sebastian Rittau
2024-05-10 04:50:07 +02:00
committed by GitHub
parent 392ae934fc
commit 27cad856f8
35 changed files with 668 additions and 0 deletions

View File

@@ -44,6 +44,7 @@
"stubs/defusedxml",
"stubs/docker",
"stubs/docutils",
"stubs/flake8",
"stubs/Flask-SocketIO",
"stubs/fpdf2",
"stubs/google-cloud-ndb",

View File

@@ -0,0 +1,4 @@
flake8.__main__
# Can't reconcile @cached_property with @property.
flake8.processor.FileProcessor.file_tokens

View File

@@ -0,0 +1,3 @@
version = "7.0.*"
upstream_repository = "https://github.com/pycqa/flake8"
requires = ["types-pyflakes"]

View File

@@ -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: ...

View File

@@ -0,0 +1,5 @@
from typing import Final
FSTRING_START: Final[int]
FSTRING_MIDDLE: Final[int]
FSTRING_END: Final[int]

View File

View File

@@ -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: ...

View File

@@ -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]: ...

View File

@@ -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]]

View File

@@ -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]: ...

View File

@@ -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: ...

View File

@@ -0,0 +1 @@
terminal_supports_color: bool

View File

@@ -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: ...

View File

@@ -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: ...

View File

View File

@@ -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: ...

View File

@@ -0,0 +1,3 @@
from collections.abc import Sequence
def main(argv: Sequence[str] | None = None) -> int: ...

View File

@@ -0,0 +1,5 @@
from typing import Any
from ..plugins.finder import Plugins
def information(version: str, plugins: Plugins) -> dict[str, Any]: ...

View File

@@ -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: ...

View File

View File

@@ -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: ...

View File

@@ -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]: ...

View File

@@ -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: ...

View File

@@ -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]: ...

View File

View File

@@ -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: ...

View File

@@ -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]: ...

View File

@@ -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]: ...

View File

@@ -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: ...

View File

@@ -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: ...

View File

@@ -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: ...

View File

@@ -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: ...

View File

@@ -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: ...

View File

@@ -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: ...