Skip to content

Fix mypy pre-commit settings#148

Merged
hugovk merged 1 commit into
python:mainfrom
potiuk:fix-mypy-pre-commit
Nov 21, 2024
Merged

Fix mypy pre-commit settings#148
hugovk merged 1 commit into
python:mainfrom
potiuk:fix-mypy-pre-commit

Conversation

@potiuk

@potiuk potiuk commented Nov 17, 2024

Copy link
Copy Markdown
Contributor

When proposing #147 I noticed that mypy failed with missing types-request - and while the mypy configuration had the --install-types, it did not work automatically for requests.

The error was:

cherry_picker/cherry_picker.py:15: error: Library stubs not installed for
"requests"  [import-untyped]
    import requests
    ^
cherry_picker/cherry_picker.py:15: note: Hint: "python3 -m pip install types-requests"
cherry_picker/cherry_picker.py:15: note: (or run "mypy --install-types" to install all missing stub packages)
cherry_picker/cherry_picker.py:15: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

I looked a bit closer and noticed the advice from
https://github.com/pre-commit/mirrors-mypy

Note that using the --install-types is problematic. Mutating the
pre-commit environment at runtime breaks cache and will break parallel builds.

This PR fixes the problem by removing --install-types and installing types-requests explicitly as additional-dependencies.

starting

When proposing python#147 I noticed that mypy failed with missing
`types-request` - and while the mypy configuration had
the `--install-types`, it did not work automatically for requests.

The error was:

```
cherry_picker/cherry_picker.py:15: error: Library stubs not installed for
"requests"  [import-untyped]
    import requests
    ^
cherry_picker/cherry_picker.py:15: note: Hint: "python3 -m pip install types-requests"
cherry_picker/cherry_picker.py:15: note: (or run "mypy --install-types" to install all missing stub packages)
cherry_picker/cherry_picker.py:15: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
```

I looked a bit closer and noticed the advice from
https://github.com/pre-commit/mirrors-mypy

> Note that using the --install-types is problematic. Mutating the
pre-commit environment at runtime breaks cache and will break parallel
builds.

This PR fixes the problem by removing `--install-types` and installing
types-requests explicitly as additional-dependencies.

starting
@hugovk

hugovk commented Nov 17, 2024

Copy link
Copy Markdown
Member

See also #144.

@potiuk

potiuk commented Nov 17, 2024

Copy link
Copy Markdown
Contributor Author

Ah. Yeahl. I see. Feel free to close it, just note this thing as well:

Note that using the --install-types is problematic. Mutating the
pre-commit environment at runtime breaks cache and will break parallel builds.

It's also the reason (it already hit us back in the past) why we don not use --install-types in Airflow but pre-install all needed types stubs:

https://github.com/apache/airflow/blob/main/hatch_build.py#L215

Mypy 0.900 and above ships only with stubs from stdlib so if we need other stubs, we need to install them
manually as types-*. See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
for details. We want to install them explicitly because we want to eventually move to
mypyd which does not support installing the types dynamically with --install-types

So you might consider removing both --installl-types and --non-interactive (the latter is only accepted when --install-types is used).

@hugovk hugovk merged commit 452a9b2 into python:main Nov 21, 2024
@hugovk

hugovk commented Nov 21, 2024

Copy link
Copy Markdown
Member

Thank you!

@hugovk hugovk mentioned this pull request Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants