Update hooks and use autopep8 + add-trailing-comma instead of black

This commit is contained in:
Max R 2025-07-20 19:12:27 -04:00
parent 23d2a8517e
commit 5fab0d1887
33 changed files with 110 additions and 102 deletions

View file

@ -97,7 +97,7 @@ def mock_file_checker_with_plugin(plugin_target):
# Prevent it from reading lines from stdin or somewhere else
with mock.patch(
"flake8.processor.FileProcessor.read_lines", return_value=["Line 1"]
"flake8.processor.FileProcessor.read_lines", return_value=["Line 1"],
):
file_checker = checker.FileChecker(
filename="-",
@ -325,12 +325,12 @@ def test_handling_syntaxerrors_across_pythons():
if sys.version_info < (3, 10): # pragma: no cover (<3.10)
# Python 3.9 or older
err = SyntaxError(
"invalid syntax", ("<unknown>", 2, 5, "bad python:\n")
"invalid syntax", ("<unknown>", 2, 5, "bad python:\n"),
)
expected = (2, 4)
else: # pragma: no cover (3.10+)
err = SyntaxError(
"invalid syntax", ("<unknown>", 2, 1, "bad python:\n", 2, 11)
"invalid syntax", ("<unknown>", 2, 1, "bad python:\n", 2, 11),
)
expected = (2, 1)
file_checker = checker.FileChecker(

View file

@ -314,7 +314,7 @@ def test_cli_config_option_respected(tmp_path):
"""\
[flake8]
ignore = F401
"""
""",
)
py_file = tmp_path / "t.py"
@ -330,7 +330,7 @@ def test_cli_isolated_overrides_config_option(tmp_path):
"""\
[flake8]
ignore = F401
"""
""",
)
py_file = tmp_path / "t.py"
@ -364,7 +364,7 @@ def test_output_file(tmpdir, capsys):
def test_early_keyboard_interrupt_does_not_crash(capsys):
with mock.patch.object(
config, "load_config", side_effect=KeyboardInterrupt
config, "load_config", side_effect=KeyboardInterrupt,
):
assert cli.main(["does-not-exist"]) == 1
out, err = capsys.readouterr()

View file

@ -86,7 +86,7 @@ def test_local_plugin_can_add_option(local_config):
stage1_args, rest = stage1_parser.parse_known_args(argv)
cfg, cfg_dir = config.load_config(
config=stage1_args.config, extra=[], isolated=False
config=stage1_args.config, extra=[], isolated=False,
)
opts = finder.parse_plugin_options(

View file

@ -42,7 +42,7 @@ def test_plugins_all_plugins():
logical_line_plugin = _loaded(parameters={"logical_line": True})
physical_line_plugin = _loaded(parameters={"physical_line": True})
report_plugin = _loaded(
plugin=_plugin(ep=_ep(name="R", group="flake8.report"))
plugin=_plugin(ep=_ep(name="R", group="flake8.report")),
)
plugins = finder.Plugins(
@ -200,14 +200,16 @@ def test_flake8_plugins(flake8_dist, mock_distribution):
"flake8",
"9001",
importlib.metadata.EntryPoint(
"default", "flake8.formatting.default:Default", "flake8.report"
"default",
"flake8.formatting.default:Default",
"flake8.report",
),
),
finder.Plugin(
"flake8",
"9001",
importlib.metadata.EntryPoint(
"pylint", "flake8.formatting.default:Pylint", "flake8.report"
"pylint", "flake8.formatting.default:Pylint", "flake8.report",
),
),
}
@ -270,7 +272,7 @@ unrelated = unrelated:main
"flake8-foo",
"1.2.3",
importlib.metadata.EntryPoint(
"Q", "flake8_foo:Plugin", "flake8.extension"
"Q", "flake8_foo:Plugin", "flake8.extension",
),
),
finder.Plugin(
@ -304,21 +306,23 @@ unrelated = unrelated:main
"flake8",
"9001",
importlib.metadata.EntryPoint(
"default", "flake8.formatting.default:Default", "flake8.report"
"default",
"flake8.formatting.default:Default",
"flake8.report",
),
),
finder.Plugin(
"flake8",
"9001",
importlib.metadata.EntryPoint(
"pylint", "flake8.formatting.default:Pylint", "flake8.report"
"pylint", "flake8.formatting.default:Pylint", "flake8.report",
),
),
finder.Plugin(
"flake8-foo",
"1.2.3",
importlib.metadata.EntryPoint(
"foo", "flake8_foo:Formatter", "flake8.report"
"foo", "flake8_foo:Formatter", "flake8.report",
),
),
}
@ -485,28 +489,30 @@ def test_find_plugins(
"flake8",
"9001",
importlib.metadata.EntryPoint(
"default", "flake8.formatting.default:Default", "flake8.report"
"default",
"flake8.formatting.default:Default",
"flake8.report",
),
),
finder.Plugin(
"flake8",
"9001",
importlib.metadata.EntryPoint(
"pylint", "flake8.formatting.default:Pylint", "flake8.report"
"pylint", "flake8.formatting.default:Pylint", "flake8.report",
),
),
finder.Plugin(
"flake8-foo",
"1.2.3",
importlib.metadata.EntryPoint(
"Q", "flake8_foo:Plugin", "flake8.extension"
"Q", "flake8_foo:Plugin", "flake8.extension",
),
),
finder.Plugin(
"flake8-foo",
"1.2.3",
importlib.metadata.EntryPoint(
"foo", "flake8_foo:Formatter", "flake8.report"
"foo", "flake8_foo:Formatter", "flake8.report",
),
),
finder.Plugin(
@ -518,7 +524,7 @@ def test_find_plugins(
"local",
"local",
importlib.metadata.EntryPoint(
"Y", "mod2:attr", "flake8.extension"
"Y", "mod2:attr", "flake8.extension",
),
),
finder.Plugin(
@ -723,7 +729,7 @@ def test_import_plugins_extends_sys_path():
def test_classify_plugins():
report_plugin = _loaded(
plugin=_plugin(ep=_ep(name="R", group="flake8.report"))
plugin=_plugin(ep=_ep(name="R", group="flake8.report")),
)
tree_plugin = _loaded(parameters={"tree": True})
logical_line_plugin = _loaded(parameters={"logical_line": True})

View file

@ -25,7 +25,7 @@ def reporters():
"flake8",
"123",
importlib.metadata.EntryPoint(
name, f"{cls.__module__}:{cls.__name__}", "flake8.report"
name, f"{cls.__module__}:{cls.__name__}", "flake8.report",
),
),
cls,
@ -72,5 +72,5 @@ def test_make_formatter_format_string(reporters, caplog):
"flake8.plugins.reporter",
30,
"'hi %(code)s' is an unknown formatter. Falling back to default.",
)
),
]

View file

@ -36,7 +36,7 @@ def application():
],
)
def test_application_exit_code(
result_count, catastrophic, exit_zero, value, application
result_count, catastrophic, exit_zero, value, application,
):
"""Verify Application.exit_code returns the correct value."""
application.result_count = result_count

View file

@ -50,7 +50,7 @@ def test_format_needs_to_be_implemented():
formatter = base.BaseFormatter(options())
with pytest.raises(NotImplementedError):
formatter.format(
Violation("A000", "file.py", 1, 1, "error text", None)
Violation("A000", "file.py", 1, 1, "error text", None),
)
@ -59,7 +59,7 @@ def test_show_source_returns_nothing_when_not_showing_source():
formatter = base.BaseFormatter(options(show_source=False))
assert (
formatter.show_source(
Violation("A000", "file.py", 1, 1, "error text", "line")
Violation("A000", "file.py", 1, 1, "error text", "line"),
)
== ""
)
@ -70,7 +70,7 @@ def test_show_source_returns_nothing_when_there_is_source():
formatter = base.BaseFormatter(options(show_source=True))
assert (
formatter.show_source(
Violation("A000", "file.py", 1, 1, "error text", None)
Violation("A000", "file.py", 1, 1, "error text", None),
)
== ""
)

View file

@ -14,7 +14,7 @@ def test_debug_information():
pkg,
version,
importlib.metadata.EntryPoint(
ep_name, "dne:dne", "flake8.extension"
ep_name, "dne:dne", "flake8.extension",
),
),
None,

View file

@ -35,7 +35,7 @@ def create_options(**kwargs):
def test_was_ignored_ignores_errors(ignore_list, extend_ignore, error_code):
"""Verify we detect users explicitly ignoring an error."""
decider = style_guide.DecisionEngine(
create_options(ignore=ignore_list, extend_ignore=extend_ignore)
create_options(ignore=ignore_list, extend_ignore=extend_ignore),
)
assert decider.was_ignored(error_code) is style_guide.Ignored.Explicitly
@ -53,11 +53,11 @@ def test_was_ignored_ignores_errors(ignore_list, extend_ignore, error_code):
],
)
def test_was_ignored_implicitly_selects_errors(
ignore_list, extend_ignore, error_code
ignore_list, extend_ignore, error_code,
):
"""Verify we detect users does not explicitly ignore an error."""
decider = style_guide.DecisionEngine(
create_options(ignore=ignore_list, extend_ignore=extend_ignore)
create_options(ignore=ignore_list, extend_ignore=extend_ignore),
)
assert decider.was_ignored(error_code) is style_guide.Selected.Implicitly
@ -179,7 +179,7 @@ def test_was_selected_excludes_errors(select_list, error_code):
],
)
def test_decision_for(
select_list, ignore_list, extend_ignore, error_code, expected
select_list, ignore_list, extend_ignore, error_code, expected,
):
"""Verify we decide when to report an error."""
decider = style_guide.DecisionEngine(
@ -187,7 +187,7 @@ def test_decision_for(
select=select_list,
ignore=ignore_list,
extend_ignore=extend_ignore,
)
),
)
assert decider.decision_for(error_code) is expected

View file

@ -47,7 +47,7 @@ def test_filenames_from_a_directory_with_a_predicate():
_filenames_from(
arg=_normpath("a/b/"),
predicate=lambda path: path.endswith(_normpath("b/c.py")),
)
),
)
# should not include c.py
expected = _normpaths(("a/b/d.py", "a/b/e/f.py"))
@ -61,7 +61,7 @@ def test_filenames_from_a_directory_with_a_predicate_from_the_current_dir():
_filenames_from(
arg=_normpath("./a/b"),
predicate=lambda path: path == "c.py",
)
),
)
# none should have matched the predicate so all returned
expected = _normpaths(("./a/b/c.py", "./a/b/d.py", "./a/b/e/f.py"))
@ -132,7 +132,7 @@ def _expand_paths(
stdin_display_name=stdin_display_name,
filename_patterns=filename_patterns,
exclude=exclude,
)
),
)

View file

@ -28,7 +28,7 @@ def _lines_from_file(tmpdir, contents, options):
def test_read_lines_universal_newlines(tmpdir, default_options):
r"""Verify that line endings are translated to \n."""
lines = _lines_from_file(
tmpdir, b"# coding: utf-8\r\nx = 1\r\n", default_options
tmpdir, b"# coding: utf-8\r\nx = 1\r\n", default_options,
)
assert lines == ["# coding: utf-8\n", "x = 1\n"]
@ -36,7 +36,7 @@ def test_read_lines_universal_newlines(tmpdir, default_options):
def test_read_lines_incorrect_utf_16(tmpdir, default_options):
"""Verify that an incorrectly encoded file is read as latin-1."""
lines = _lines_from_file(
tmpdir, b"# coding: utf16\nx = 1\n", default_options
tmpdir, b"# coding: utf16\nx = 1\n", default_options,
)
assert lines == ["# coding: utf16\n", "x = 1\n"]
@ -44,7 +44,7 @@ def test_read_lines_incorrect_utf_16(tmpdir, default_options):
def test_read_lines_unknown_encoding(tmpdir, default_options):
"""Verify that an unknown encoding is still read as latin-1."""
lines = _lines_from_file(
tmpdir, b"# coding: fake-encoding\nx = 1\n", default_options
tmpdir, b"# coding: fake-encoding\nx = 1\n", default_options,
)
assert lines == ["# coding: fake-encoding\n", "x = 1\n"]
@ -289,7 +289,7 @@ def test_processor_split_line(default_options):
def test_build_ast(default_options):
"""Verify the logic for how we build an AST for plugins."""
file_processor = processor.FileProcessor(
"-", default_options, lines=["a = 1\n"]
"-", default_options, lines=["a = 1\n"],
)
module = file_processor.build_ast()
@ -299,7 +299,7 @@ def test_build_ast(default_options):
def test_next_logical_line_updates_the_previous_logical_line(default_options):
"""Verify that we update our tracking of the previous logical line."""
file_processor = processor.FileProcessor(
"-", default_options, lines=["a = 1\n"]
"-", default_options, lines=["a = 1\n"],
)
file_processor.indent_level = 1
@ -315,7 +315,7 @@ def test_next_logical_line_updates_the_previous_logical_line(default_options):
def test_visited_new_blank_line(default_options):
"""Verify we update the number of blank lines seen."""
file_processor = processor.FileProcessor(
"-", default_options, lines=["a = 1\n"]
"-", default_options, lines=["a = 1\n"],
)
assert file_processor.blank_lines == 0

View file

@ -6,7 +6,7 @@ from flake8.main import options
def test_stage1_arg_parser():
stage1_parser = options.stage1_arg_parser()
opts, args = stage1_parser.parse_known_args(
["--foo", "--verbose", "src", "setup.py", "--statistics", "--version"]
["--foo", "--verbose", "src", "setup.py", "--statistics", "--version"],
)
assert opts.verbose

View file

@ -122,7 +122,7 @@ def test_parse_args_handles_comma_separated_defaults(optmanager):
assert optmanager.config_options_dict == {}
optmanager.add_option(
"--exclude", default="E123,W234", comma_separated_list=True
"--exclude", default="E123,W234", comma_separated_list=True,
)
options = optmanager.parse_args([])
@ -135,7 +135,7 @@ def test_parse_args_handles_comma_separated_lists(optmanager):
assert optmanager.config_options_dict == {}
optmanager.add_option(
"--exclude", default="E123,W234", comma_separated_list=True
"--exclude", default="E123,W234", comma_separated_list=True,
)
options = optmanager.parse_args(["--exclude", "E201,W111,F280"])
@ -148,11 +148,11 @@ def test_parse_args_normalize_paths(optmanager):
assert optmanager.config_options_dict == {}
optmanager.add_option(
"--extra-config", normalize_paths=True, comma_separated_list=True
"--extra-config", normalize_paths=True, comma_separated_list=True,
)
options = optmanager.parse_args(
["--extra-config", "../config.ini,tox.ini,flake8/some-other.cfg"]
["--extra-config", "../config.ini,tox.ini,flake8/some-other.cfg"],
)
assert options.extra_config == [
os.path.abspath("../config.ini"),

View file

@ -169,7 +169,7 @@ def test_load_extra_config_utf8(tmpdir):
@pytest.fixture
def opt_manager():
ret = OptionManager(
version="123", plugin_versions="", parents=[], formatter_names=[]
version="123", plugin_versions="", parents=[], formatter_names=[],
)
register_default_options(ret)
return ret
@ -213,7 +213,7 @@ def test_parse_config_ignores_unknowns(tmp_path, opt_manager, caplog):
"flake8.options.config",
10,
'Option "wat" is not registered. Ignoring.',
)
),
]

View file

@ -36,7 +36,7 @@ def test_handle_error_does_not_raise_type_errors():
)
assert 1 == guide.handle_error(
"T111", "file.py", 1, 1, "error found", "a = 1"
"T111", "file.py", 1, 1, "error found", "a = 1",
)
@ -110,7 +110,7 @@ def test_style_guide_manager_pre_file_ignores_parsing():
],
)
def test_style_guide_manager_pre_file_ignores(
ignores, violation, filename, handle_error_return
ignores, violation, filename, handle_error_return,
):
"""Verify how the StyleGuideManager creates a default style guide."""
formatter = mock.create_autospec(base.BaseFormatter, instance=True)