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

Default ignore overrides default select but explicit select overrides default ignore #1687

Closed
lafrech opened this issue Sep 15, 2022 · 5 comments
Labels

Comments

@lafrech
Copy link

lafrech commented Sep 15, 2022

how did you install flake8?

pip install flake8

unmodified output of flake8 --bug-report

{
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.9.2",
    "system": "Linux"
  },
  "plugins": [
    {
      "plugin": "mccabe",
      "version": "0.7.0"
    },
    {
      "plugin": "pycodestyle",
      "version": "2.9.1"
    },
    {
      "plugin": "pyflakes",
      "version": "2.5.0"
    }
  ],
  "version": "5.0.4"
}

describe the problem

I'm seeing a strange behaviour with select/ignore arguments and their defaults. I think it appeared in flake8 5.x and I believe it is neither documented nor intuitive (but I could be proven wrong).

The --help menu displays the default values for ignore and select:

  --ignore errors       Comma-separated list of error codes to ignore (or skip). For example, ``--ignore=E4,E51,W234``. (Default:
                        E121,E123,E126,E226,E24,E704,W503,W504)
  --select errors       Comma-separated list of error codes to enable. For example, ``--select=E4,E51,W234``. (Default: E,F,W,C90)

As expected, explicitly passing those values in a config file leads to a behaviour identical to the default one:

[flake8]
select = E,F,W,C90
ignore = E121,E123,E126,E226,E24,E704,W503,W504

is identical to

[flake8]
# select = E,F,W,C90
# ignore = E121,E123,E126,E226,E24,E704,W503,W504

In both cases, the ignore value overrides the select value and W503 errors are ignored.

What comes as a surprise is that select passed explicitly, even if its value is the default one, is not overridden by default ignore.

[flake8]
select = E,F,W,C90
# ignore = E121,E123,E126,E226,E24,E704,W503,W504

In this case, W503 is not ignored.


In other words, it looks like the precedence order is the following:

explicit ignore
explicit select
default ignore
default select

while one (I, at least) would expect

explicit ignore
default ignore
explicit select
default select

In the latter case, an explicit value would only override a default one, but would not interfere with ignore overriding select.

Same applies if a code or class is added with extend-select (not with flake8 < 5, see below). It will only be ignored if explicitly added to ignore or extend-ignore. I'm using the form without extend- above for brevity.


After further investigation, the behaviour is the same with earlier versions of flake8, except that the tests above will not show it because when the value passed as select is the same as the default, the option is ignored. This changed in flake8 5.x (#284, #1609). Modifying select to something slightly different such as E,F,W,C9 instead of E,F,W,C90 will show that explicit select of W overrides default ignore of W503.

With flake8 4.x, extend-select doesn't seem to override default ignore while it does with flake8 5.x.

I'm not sure what is intended and what is not, here.


In practice, the problem in my codebase appeared because the config file dates back to when extend-select didn't exist so we used select and we had to specify all the default codes in there. extend-select now allows us to only add the ones we want, therefore we don't have to specify W which would override default ignore of W503. So we can get away with it by switching to extend-select.

I still think this behaviour is strange but maybe I haven't dived long enough in the docs and I shouldn't be surprised the actual behaviour doesn't follow my expectations. Feel free to close. Thanks for reading. I hope I'm making sense.

@asottile
Copy link
Member

in 5.x it was changed such that explicit opt-ins are respected -- before they were silently treated as implicit

@asottile
Copy link
Member

fwiw you almost never need select or extend-select since plugins are added to select by default simply by being installed

@lafrech
Copy link
Author

lafrech commented Sep 15, 2022

in 5.x it was changed such that explicit opt-ins are respected -- before they were silently treated as implicit

OK I guess this makes sense, I just expected otherwise and it wasn't obvious to find out when the error appeared on update.

Thanks for the hint.

@asottile
Copy link
Member

lol why do I bother writing a changelog 🙃

@lafrech
Copy link
Author

lafrech commented Sep 15, 2022

I found the release notes after a bit of searching but even then the implications were not clear to me.

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

No branches or pull requests

2 participants