Skip to content

Commit 1bc2264

Browse files
authored
add workaround for flake8_6 enforcing three-letter codes in config to readme. Add tests (#234)
1 parent e1d1d32 commit 1bc2264

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ flake8-async **/*.py
123123
but we prefer using a config file. The file needs to start with a section marker `[flake8]` and the following options are then parsed using flake8's config parser, and can be used just like any other flake8 options.
124124
Note that it's not currently possible to use a configuration file when running `flake8-async` standalone.
125125

126+
### `ValueError` when trying to `ignore` error codes in config file
127+
Error codes with more than three letters are not possible to `ignore` in config files since flake8>=6, as flake8 tries to validate correct configuration with a regex. We have decided not to conform to this, as it would be a breaking change for end-users requiring them to update `noqa`s and configurations, we think the `ASYNC` code is much more readable than e.g. `ASYxxx`, and ruff does not enforce such a limit. The easiest option for users hitting this error is to instead use the `--disable` option as documented [below](#--disable). See further discussion and other workarounds in https://github.com/python-trio/flake8-async/issues/230
128+
126129
### `--enable`
127130
Comma-separated list of error codes to enable, similar to flake8 --select but is additionally more performant as it will disable non-enabled visitors from running instead of just silencing their errors.
128131

tests/test_config_and_args.py

+31
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ def _test_trio200_from_config_common(tmp_path: Path) -> str:
210210
other -> async,
211211
sync_fns.* -> the_async_equivalent,
212212
select = ASYNC200
213+
extend-ignore = E
213214
"""
214215
)
215216
assert tmp_path.joinpath("example.py").write_text(
@@ -403,3 +404,33 @@ def test_disable_noqa_ast(
403404
== "./example.py:1:1: ASYNC106 trio must be imported with `import trio` for the"
404405
" linter to work.\n"
405406
)
407+
408+
409+
@pytest.mark.xfail(reason="flake8>=6 enforces three-letter error codes in config")
410+
def test_config_ignore_error_code(tmp_path: Path) -> None:
411+
assert tmp_path.joinpath(".flake8").write_text(
412+
"""
413+
[flake8]
414+
ignore = ASYNC100
415+
"""
416+
)
417+
res = subprocess.run(
418+
["flake8", "--help"], cwd=tmp_path, capture_output=True, check=False
419+
)
420+
assert not res.stderr
421+
assert res.returncode == 0
422+
423+
424+
# but make sure we can disable selected codes
425+
def test_config_disable_error_code(tmp_path: Path) -> None:
426+
# select ASYNC200 and create file that induces ASYNC200
427+
_test_trio200_from_config_common(tmp_path)
428+
# disable ASYNC200
429+
with open(tmp_path.joinpath(".flake8"), "a", encoding="utf-8") as file:
430+
file.write("disable = ASYNC200")
431+
432+
# it now returns no errors
433+
res = subprocess.run(["flake8"], cwd=tmp_path, capture_output=True, check=True)
434+
assert not res.stdout
435+
assert not res.stderr
436+
assert res.returncode == 0

0 commit comments

Comments
 (0)