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

flake8 pre-commit config incompatible with 3.12 #1670

Closed
EliahKagan opened this issue Sep 21, 2023 · 0 comments · Fixed by #1673
Closed

flake8 pre-commit config incompatible with 3.12 #1670

EliahKagan opened this issue Sep 21, 2023 · 0 comments · Fixed by #1673

Comments

@EliahKagan
Copy link
Contributor

EliahKagan commented Sep 21, 2023

The configuration for flake8 in .pre-commit-config.yaml--specifically that version 6.0.0 is used--is incompatible with Python 3.12, producing an incorrect "E231 missing whitespace after ':'" error:

(.venv) ek@Glub:~/repos-wsl/GitPython (scripts)$ pre-commit run --all-files
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

git/cmd.py:479:34: E231 missing whitespace after ':'
                f"The `{protocol}::` protocol looks suspicious, use `allow_unsafe_protocols=True` to allow it."
                                 ^
git/cmd.py:479:35: E231 missing whitespace after ':'
                f"The `{protocol}::` protocol looks suspicious, use `allow_unsafe_protocols=True` to allow it."
                                  ^
git/refs/log.py:247:67: E226 missing whitespace around arithmetic operator
                    raise IndexError(f"Index file ended at line {i+1}, before given index was reached")
                                                                  ^
1     E226 missing whitespace around arithmetic operator
2     E231 missing whitespace after ':'
3

check for merge conflicts................................................Passed
check toml...............................................................Passed
check yaml...............................................................Passed

It also reports E226, which also happens only on Python 3.12, but appears intentional. But that's easy to fix (the simplest way being to add the spaces it wants, which also more resembles the overall style for the + operator in this project).

The wrong : error (false positive E231) happens because flake8 6.0.0 depends on pycodestyle 2.10.*, which implements that check (E231) and has a parsing bug specific to Python 3.12. This was fixed in PyCQA/pycodestyle#1148.

Upgrading to flake8 6.1.0 gets the fix, since that version of flake8, currently the latest, depends on pycodestyle 2.11.*, which has it:

(.venv) ek@Glub:~/repos-wsl/GitPython (scripts)$ pre-commit autoupdate
[/~https://github.com/PyCQA/flake8] updating 6.0.0 -> 6.1.0
[/~https://github.com/pre-commit/pre-commit-hooks] already up to date!
(.venv) ek@Glub:~/repos-wsl/GitPython (scripts *)$ pre-commit run --all-files
[INFO] Installing environment for /~https://github.com/PyCQA/flake8.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

git/objects/submodule/base.py:1406:16: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
            if type(sm) != git.objects.submodule.base.Submodule:
               ^
git/refs/log.py:247:67: E226 missing whitespace around arithmetic operator
                    raise IndexError(f"Index file ended at line {i+1}, before given index was reached")
                                                                  ^
git/util.py:1139:16: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
            if type(base) == IterableClassWatcher:
               ^
1     E226 missing whitespace around arithmetic operator
2     E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
3

check for merge conflicts................................................Passed
check toml...............................................................Passed
check yaml...............................................................Passed

However, that reports E721 about the use of == to compare to a type object. So I think it makes sense for a fix for this to be part of a larger change that also fixes the new problems found by flake8, also bumps versions on the listed flake8 plugins (other than the default ones like pycodestyle) and fixes new warnings from that, and possibly addresses other style issues and/or expands the scope of flake8 checks to cover the test suite. (The benefit of the latter is that it could reveal areas where the checks ought to be configured differently.) I plan to open such a PR shortly.

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

Successfully merging a pull request may close this issue.

2 participants