Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend-ignore and extend-select options seem to be ignored #221

Open
rodelrod opened this issue Jan 30, 2022 · 8 comments · Fixed by #218
Open

extend-ignore and extend-select options seem to be ignored #221

rodelrod opened this issue Jan 30, 2022 · 8 comments · Fixed by #218

Comments

@rodelrod
Copy link

rodelrod commented Jan 30, 2022

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
@cooperlees
Copy link
Collaborator

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.

@rodelrod
Copy link
Author

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.

@sco1
Copy link
Contributor

sco1 commented Jan 31, 2022

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

flake8-bugbear/bugbear.py

Lines 152 to 154 in 1c47a16

for i in range(2, len(code) + 1):
if code[:i] in self.options.select:
return True

There is some talk in #218 (comment) about removing the should_warn method entirely & deferring to flake8's handling, which I'm assuming would solve this.

@sjdemartini
Copy link

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

@cooperlees cooperlees reopened this Apr 6, 2022
@sco1
Copy link
Contributor

sco1 commented Apr 7, 2022

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

@sjdemartini
Copy link

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?

@sco1
Copy link
Contributor

sco1 commented Apr 7, 2022

Before PyCQA/flake8#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.

@jack-tutor
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants