flake8-bugbear icon indicating copy to clipboard operation
flake8-bugbear copied to clipboard

`extend-ignore` and `extend-select` options seem to be ignored

Open rodelrod opened this issue 2 years ago • 8 comments

If I use --extend-ignore or --extend-select options, B950 is not taken into account.

OK:

▹ flake8 --select=E,B950  longline.py
longline.py:1:80: E501 line too long (109 > 79 characters)
longline.py:1:110: B950 line too long (109 > 79 characters)

▹ flake8 --select=E,B950 --ignore=E501 longline.py
longline.py:1:110: B950 line too long (109 > 79 characters)

Not OK:

▹ flake8 --extend-select=E,B950 longline.py
longline.py:1:80: E501 line too long (109 > 79 characters)

▹ flake8 --extend-select=E,B950 --ignore=E501 longline.py

▸ flake8 --select=E,B950 --extend-ignore=E501 longline.py

Versions:

▸ flake8 --version
4.0.1 (flake8-bugbear: 22.1.11, mccabe: 0.6.1, pycodestyle: 2.8.0,
pyflakes: 2.4.0) CPython 3.10.1 on Linux

rodelrod avatar Jan 30 '22 14:01 rodelrod

Thanks for reporting. What does this plugin need to do to fix this? Happy to take a PR that fixes it. Will dig in if I get some time eventually.

cooperlees avatar Jan 30 '22 22:01 cooperlees

What does this plugin need to do to fix this?

@cooperlees I don't know, I hadn't heard of this plugin until yesterday. It looks helpful, thanks for your work.

I was following Black's documentation suggesting a configuration that did not work for me because of this issue.

I've just stopped using extend- and moved on, but would like others not to waste time with this.

rodelrod avatar Jan 31 '22 16:01 rodelrod

Bugbear's built-in filtering for opinionated warnings isn't aware of extend-select, since the code predates its addition to flake8:

https://github.com/PyCQA/flake8-bugbear/blob/1c47a162d4b2c41ada9164a12b536d6f49833d7e/bugbear.py#L152-L154

There is some talk in https://github.com/PyCQA/flake8-bugbear/pull/218#issuecomment-1012533478 about removing the should_warn method entirely & deferring to flake8's handling, which I'm assuming would solve this.

sco1 avatar Jan 31 '22 18:01 sco1

I'm finding that extend-select still does not work when used as in the example https://github.com/PyCQA/flake8-bugbear#how-to-enable-opinionated-warnings

[flake8]
max-line-length = 80
max-complexity = 12
extend-ignore = E501
extend-select = B950

When I use that, I do see that E501 is ignored, but B950 does not go into effect. By contrast, if I use:

[flake8]
max-line-length = 80
max-complexity = 12
select = B950

I see the B950 line too long violation show up. I'm not sure if extend-select being ignored is an issue in flake8-bugbear or in flake8 itself, but it seems this issue should be reopened.

I'm running the latest flake8 and flake8-bugbear:

$ flake8 --version
4.0.1 (flake8-bugbear: 22.3.23, flake8_isort: 4.1.1, mccabe: 0.6.1, pycodestyle: 2.8.0, pyflakes: 2.4.0) CPython 3.8.3 on Darwin

sjdemartini avatar Apr 06 '22 18:04 sjdemartini

Can you reproduce with flake8@main? This may be https://github.com/PyCQA/flake8/issues/284 (e.g. https://gist.github.com/sco1/7c544878bde10163258435f9e8ae5b11), which is fixed but not part of a release yet.

sco1 avatar Apr 07 '22 00:04 sco1

Thanks for getting back to me @sco1 (and re-opening cooperlees), and promising that there's an update in flake8 that may fix this!

I tried the latest flake8 main with extend-select and extend-ignore, but encountered a new crash in flake8-bugbear:

Traceback (most recent call last):
  File "/Users/.../venv/bin/flake8", line 8, in <module>
    sys.exit(main())
  File "/Users/.../venv/lib/python3.8/site-packages/flake8/main/cli.py", line 22, in main
    app.run(argv)
  File "/Users/.../venv/lib/python3.8/site-packages/flake8/main/application.py", line 336, in run
    self._run(argv)
  File "/Users/.../venv/lib/python3.8/site-packages/flake8/main/application.py", line 325, in _run
    self.run_checks()
  File "/Users/.../venv/lib/python3.8/site-packages/flake8/main/application.py", line 229, in run_checks
    self.file_checker_manager.run()
  File "/Users/.../venv/lib/python3.8/site-packages/flake8/checker.py", line 252, in run
    self.run_serial()
  File "/Users/.../venv/lib/python3.8/site-packages/flake8/checker.py", line 237, in run_serial
    checker.run_checks()
  File "/Users/.../venv/lib/python3.8/site-packages/flake8/checker.py", line 531, in run_checks
    self.run_ast_checks()
  File "/Users/.../venv/lib/python3.8/site-packages/flake8/checker.py", line 435, in run_ast_checks
    for (line_number, offset, text, _) in runner:
  File "/Users/.../venv/lib/python3.8/site-packages/bugbear.py", line 61, in run
    if self.should_warn(e.message[:4]):
  File "/Users/.../venv/lib/python3.8/site-packages/bugbear.py", line 158, in should_warn
    if code[:i] in self.options.select:
TypeError: argument of type 'NoneType' is not iterable

Guessing from the stacktrace that this is because I don't have select specified, but only extend-select, and that's not handled in bugbear with the new way flake8 organizes these things?

sjdemartini avatar Apr 07 '22 17:04 sjdemartini

Before https://github.com/PyCQA/flake8/pull/1576 it wasn't possible for select to be empty but the PR appears to have gotten rid of the default value. Flake8 has a bit of a complicated mechanism for handling & merging configurations that I'm not very familiar with, so I'm not sure how to best adjust bugbear to maintain compatibility.

It might be a better upstream question, though one answer we have already is to get rid of this block entirely.

sco1 avatar Apr 07 '22 19:04 sco1

I am also running into this issue - also on latest flake and bugbear.

jack-tutor avatar Jul 13 '22 00:07 jack-tutor