-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[pre-commit] Fix local pre-commit installation for python != 3.8 #12869
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
[pre-commit] Fix local pre-commit installation for python != 3.8 #12869
Conversation
e1b17d5
to
213eff8
Compare
213eff8
to
cf7c1fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Pierre-Sassoulas and @The-Compiler!
Backport to 8.3.x: 💚 backport PR created✅ Backport PR branch: Backported as #12871 🤖 @patchback |
…n interpreter (#12869) (#12871) (cherry picked from commit 2242cd4) Co-authored-by: Pierre Sassoulas <[email protected]>
Might be better to set this in |
@@ -32,8 +32,7 @@ repos: | |||
hooks: | |||
- id: mypy | |||
files: ^(src/|testing/|scripts/) | |||
args: [] | |||
language_version: "3.8" | |||
args: ["--python-version=3.8"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my other projects, I started running MyPy against multiple Python versions, keeping all the shared configuration in the config and only setting the diverging options in pre-commit: https://github.com/ansible/awx-plugins/blob/0b3155e/.pre-commit-config.yaml#L188-L280 / https://github.com/ansible/awx-plugins/blob/0b3155e/.mypy.ini#L1-L58.
Listing every supported version is possible, but is probably too much, so I was doing it for every other version. To reduce the number of calls even more, it's also possible to just run against minimum and maximum supported versions…
In my example, I've also introduced per-version aliases that are useful for local development to run less things while actively fixing stuff.
I'm hoping to bring this approach to pytest one day.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running against python 3.13 we have:
src/_pytest/pathlib.py:704: error: Argument 2 to "NamespaceLoader" has incompatible type "Path"; expected "MutableSequence[str]" [arg-type]
src/_pytest/pathlib.py:704: error: Argument 3 to "NamespaceLoader" has incompatible type "PathFinder"; expected "Callable[[str, tuple[str, ...]], ModuleSpec]" [arg-type]
src/_pytest/runner.py:170: error: Unused "type: ignore" comment [unused-ignore]
src/_pytest/runner.py:180: error: Unused "type: ignore" comment [unused-ignore]
testing/test_runner.py:1033: error: Unused "type: ignore" comment [unused-ignore]
Found 5 errors in 3 files (checked 232 source files)
Some of those messages are going to be incompatible (the unused ignore is not unused in python 3.8)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of those messages are going to be incompatible (the unused ignore is not unused in python 3.8)
I think this is a good example of disabling the check on the CLI in just one of the invocations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, those could be ignored on the respective lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if the two errors Line 704 for python 3.13 are legit. The added complexity might be worth it if they are.
I usually set in two places — the minimum version goes to |
Definitely, opened #12872 |
Refs #12868