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-select argument not working with arithmetic operator whitespace E226 #1470

Closed
gregorybchris opened this issue Nov 22, 2021 · 7 comments
Labels

Comments

@gregorybchris
Copy link

Flake8 installation

$ pip install flake8

Bug report JSON:

{
  "dependencies": [],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.8.12",
    "system": "Darwin"
  },
  "plugins": [
    {
      "is_local": false,
      "plugin": "mccabe",
      "version": "0.6.1"
    },
    {
      "is_local": false,
      "plugin": "pycodestyle",
      "version": "2.8.0"
    },
    {
      "is_local": false,
      "plugin": "pyflakes",
      "version": "2.4.0"
    }
  ],
  "version": "4.0.1"
}

My initial expectation is that flake8 should error when binary arithmetic operators are not surrounded by whitespace (E226). My further expectation is that if E226 is not enabled by default I should be able to enable it as an additional check. It seems like there might be a bug breaking E226 validation and potentially extend-select as well.

My project uses a setup.cfg configure flake8. For that reason I would like to use extend-select to avoid calling flake8 in the command line twice. The following example reproduces the issue:

Input file a.py:

a = 4-1
# E226 is not found in a.py
$ flake8 a.py
<no output>

# explicitly selecting E226 has the desired output, but will not catch other errors (by design)
$ flake8 a.py --select E226
a.py:1:6: E226 missing whitespace around arithmetic operator

# extend-select does not work as expected to catching default errors and E226
$ flake8 a.py --extend-select E226
<no output>

# ignoring all warnings somehow circumvents the issue and allows E226 to be caught
$ flake8 a.py --ignore W
a.py:1:6: E226 missing whitespace around arithmetic operator

# ignoring random text works the same way
$ flake8 a.py --ignore 0
a.py:1:6: E226 missing whitespace around arithmetic operator
@asottile
Copy link
Member

E226 is ignored by default:

IGNORE = ("E121", "E123", "E126", "E226", "E24", "E704", "W503", "W504")

@gregorybchris
Copy link
Author

gregorybchris commented Nov 22, 2021

@asottile Should I be able to enable it with --extend-select? And any idea why ignoring random text would cause that check to be enabled?

Will you please provide a solution to enable E226 checking while retaining all default validations?

@asottile
Copy link
Member

I agree it seems odd, but it appears to be intentional given #1312

And any idea why ignoring random text would cause that check to be enabled?

setting --ignore overrides the ignore list, so it removes E226 from the default ignore

@gregorybchris
Copy link
Author

gregorybchris commented Nov 22, 2021

setting --ignore overrides the ignore list

This makes sense. So --ignore 0 is not a good option because it has the side effect of overriding all default ignores.

it appears to be intentional given #1312

I'm not sure what part of #1312 indicates that --extend-select should not be usable for validations that are ignored by default. But would you agree that --extend-select should be usable for validations that are ignored by default @asottile?

@asottile
Copy link
Member

I don't think --select or --extend-select are really meant to be "override what's in --ignore", or at least there's an ambiguity when they are both selected and ignored.

I think the minimal setting to do what you want is to override the default ignore list without E226, so --ignore=E121,E123,E126,E24,E704,W503,W504

@gregorybchris
Copy link
Author

I guess that's a pretty good workaround considering the list of default ignores is so short. Thanks.

I don't think --select or --extend-select are really meant to be "override what's in --ignore"

Because I do imagine others might encounter the same problem, I'll try my best to make the case one more time. Two use cases for --extend-select:

  1. Select something that has been ignored explicitly on a less granular level.
    --ignore E --extend-select E225
  2. Select something ignored by default
    --extend-select E226

Argument 1: I do not expect whether a rule is default selected/ignored to affect whether --extend-select works. If I as the user specify that I want E226 validated (and I do not specify any conflicting settings), I see no reason why the default setting should interact with my choices.

Argument 2: Ignore and select are opposites. If I --extend-ignore something that is default selected there is not a problem ignoring it. Swapping ignore and select should not have different behavior.

Argument 3: The fact that the workaround is to re-ignore every other default ignore indicates to me that there's an issue here. The intuition behind --extend-select in the first place is to avoid long lists of ignores/selects.

@asottile
Copy link
Member

note that --extend-select E226 is somewhat nonsense because there's already --select E by default which includes E226

I'm also not here to argue, but your arguments don't really work given that

@PyCQA PyCQA locked as resolved and limited conversation to collaborators Nov 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants