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

Conversation

Pierre-Sassoulas
Copy link
Member

Refs #12868

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the fix-pre-commit-python-3.8 branch from e1b17d5 to 213eff8 Compare October 10, 2024 09:25
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicoddemus nicoddemus added skip news used on prs to opt out of the changelog requirement backport 8.3.x apply to PRs at any point; backports the changes to the 8.3.x branch labels Oct 10, 2024
@nicoddemus nicoddemus merged commit 2242cd4 into pytest-dev:main Oct 10, 2024
29 checks passed
Copy link

patchback bot commented Oct 10, 2024

Backport to 8.3.x: 💚 backport PR created

✅ Backport PR branch: patchback/backports/8.3.x/2242cd43eb5601e3f282003c049e37e56ece932a/pr-12869

Backported as #12871

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Oct 10, 2024
nicoddemus pushed a commit that referenced this pull request Oct 10, 2024
…n interpreter (#12869) (#12871)

(cherry picked from commit 2242cd4)

Co-authored-by: Pierre Sassoulas <[email protected]>
@Pierre-Sassoulas Pierre-Sassoulas deleted the fix-pre-commit-python-3.8 branch October 10, 2024 11:46
@The-Compiler
Copy link
Member

Might be better to set this in pyproject.toml rather than here? This should also be active when mypy is run via IDE or standalone, not just via pre-commit.

@@ -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.

@webknjaz
Copy link
Member

Might be better to set this in pyproject.toml rather than here? This should also be active when mypy is run via IDE or standalone, not just via pre-commit.

I usually set in two places — the minimum version goes to .mypy.ini while pre-commit adds additional versions on top. In general, I agree that the underlying tooling configs should be used whenever possible since it allows other software to pick up the same settings.

@Pierre-Sassoulas
Copy link
Member Author

Might be better to set this in pyproject.toml rather than here?

Definitely, opened #12872

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 8.3.x apply to PRs at any point; backports the changes to the 8.3.x branch skip news used on prs to opt out of the changelog requirement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants