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

ValueError on comment after ignore in .flake8 config #1756

Closed
jaap3 opened this issue Nov 24, 2022 · 3 comments
Closed

ValueError on comment after ignore in .flake8 config #1756

jaap3 opened this issue Nov 24, 2022 · 3 comments
Labels

Comments

@jaap3
Copy link

jaap3 commented Nov 24, 2022

how did you install flake8?

$ pip install -U flake8
Collecting flake8
  Downloading flake8-6.0.0-py2.py3-none-any.whl (57 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 57.8/57.8 kB 150.9 kB/s eta 0:00:00
Installing collected packages: flake8
  Attempting uninstall: flake8
    Found existing installation: flake8 5.0.4
    Uninstalling flake8-5.0.4:
      Successfully uninstalled flake8-5.0.4

unmodified output of flake8 --bug-report

{
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.8.13",
    "system": "Linux"
  },
  "plugins": [
    {
      "plugin": "flake8-black",
      "version": "0.3.5"
    },
    {
      "plugin": "flake8-isort",
      "version": "5.0.3"
    },
    {
      "plugin": "mccabe",
      "version": "0.7.0"
    },
    {
      "plugin": "pycodestyle",
      "version": "2.10.0"
    },
    {
      "plugin": "pyflakes",
      "version": "3.0.0"
    }
  ],
  "version": "6.0.0"
}

describe the problem

what I expected to happen

I have a very simple .flake8 config file

[flake8]
max-line-length = 120
ignore =
    W503  # https://www.flake8rules.com/rules/W503.html

I'd expected running flake8 after the upgrade would work, instead I get a traceback:

Traceback (most recent call last):
  File "/usr/local/bin/flake8", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/site-packages/flake8/main/cli.py", line 23, in main
    app.run(argv)
  File "/usr/local/lib/python3.8/site-packages/flake8/main/application.py", line 198, in run
    self._run(argv)
  File "/usr/local/lib/python3.8/site-packages/flake8/main/application.py", line 186, in _run
    self.initialize(argv)
  File "/usr/local/lib/python3.8/site-packages/flake8/main/application.py", line 165, in initialize
    self.plugins, self.options = parse_args(argv)
  File "/usr/local/lib/python3.8/site-packages/flake8/options/parse_args.py", line 53, in parse_args
    opts = aggregator.aggregate_options(option_manager, cfg, cfg_dir, rest)
  File "/usr/local/lib/python3.8/site-packages/flake8/options/aggregator.py", line 30, in aggregate_options
    parsed_config = config.parse_config(manager, cfg, cfg_dir)
  File "/usr/local/lib/python3.8/site-packages/flake8/options/config.py", line 131, in parse_config
    raise ValueError(
ValueError: Error code '#' supplied to 'ignore' option does not match '^[A-Z]{1,3}[0-9]{0,3}$'

In order to get the correct result for flake8 --bug-report I had to change the config file to:

[flake8]
max-line-length = 120
ignore =
    # https://www.flake8rules.com/rules/W503.html
    W503

commands ran

$ flake8
...
@jaap3
Copy link
Author

jaap3 commented Nov 24, 2022

I'm reasonably confident that having a comment after the ignore used to work.

@dimbleby
Copy link

duplicate #1753, and it's in the changelog

Apparently flake8 has always been treating these not as comments, but as additional error codes to ignore. (They just happened not to be valid error codes).

You might think that a sensible fix would have been to recognise comments, but they've instead gone with "that's not a valid error code, too bad".

Raising a feature request to ask for that would be logical, I assume that reporting it as a bug will just be dismissed.

@jaap3
Copy link
Author

jaap3 commented Nov 24, 2022

So apparently a duplicate of #1753, #1750 and #1745.

I did read the release notes, and actually also looked at the change but it seemed to be related to "invalid comments", in the style of W505 // This is not actually a comment. So I assumed this did not apply to this comment style.

For reference, the issue #1689 and PR #1713 (both linked in the release notes) do not make it clear that any type of inline comments are now considered an error.

@jaap3 jaap3 closed this as completed Nov 24, 2022
wadevries added a commit to leukeleu/leukeleu-django-checks that referenced this issue Nov 24, 2022
Flake8 version 6 now breaks on inline comments in the config.
This is a workaround for that. See PyCQA/flake8#1756
wadevries added a commit to leukeleu/leukeleu-django-gdpr that referenced this issue Nov 24, 2022
Flake8 version 6 now breaks on inline comments in the config.
This is a workaround for that. See PyCQA/flake8#1756
@PyCQA PyCQA locked as resolved and limited conversation to collaborators Nov 24, 2022
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

3 participants