Skip to content

[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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ repos:
hooks:
- id: mypy
files: ^(src/|testing/|scripts/)
args: []
language_version: "3.8"
args: ["--python-version=3.8"]
Copy link
Member

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.

Copy link
Member Author

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)

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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.

additional_dependencies:
- iniconfig>=1.1.0
- attrs>=19.2.0
Expand Down
Loading