-
Notifications
You must be signed in to change notification settings - Fork 4
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
Mypy pre-commit and editable install #5
Comments
Huh, I just found this:
|
Static type-checkers like mypy require the type annotations, which can be either inlined in in the So to answer you question:
Yes, when running mypy on your project, it'll need to have numpy available within the same environment. |
In case of pre-commit, you can also configure it to run mypy within your existing environment. For an example in a poetry-based project on mine, see e.g.: https://github.com/jorenham/optype/blob/master/.pre-commit-config.yaml#L82-L86 and for a uv-based project, see |
Okay great, looks like diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index bf0885c..97cb4c9 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -56,6 +56,8 @@ repos:
args: []
additional_dependencies:
- pytest
+ - numpy
+ - array-api-strict does the job (modulo data-apis/array-api-strict#6 (comment)). I guess it was google-able 🙃 thanks for the pointers! |
Hmm, I'm now hitting an issue with importing from this package as an editable install.
with the hook # start templated
INSTALL_PYTHON=/Users/lucascolley/.pixi/envs/pre-commit/bin/python3.12
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-commit)
# end templated
HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")
if [ -x "$INSTALL_PYTHON" ]; then
exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
elif command -v pre-commit > /dev/null; then
exec pre-commit "${ARGS[@]}"
else
echo '`pre-commit` not found. Did you forget to activate your virtualenv?' 1>&2
exit 1
fi they should both be using the same config file, so why does one fail but the other pass? |
I've fixed this for now by separating mypy from pre-commit 👍 (that seems to be the recommendation from mypy devs at least) |
Hey @jorenham, apologies for the very random question that seems google-able but I'm a bit stuck and figured you know what you are talking about when it comes to typing :)
At https://github.com/lucascolley/array-api-extra/blob/97a792a06bab290abe895eed48e4f8dcc2c0284b/tests/test_funcs.py#L3-L4 I import from some optional test dependencies including
numpy
. I have Mypy in my pre-commit hook. If I am developing in an environment without my optional test dependencies, Mypy complains about missing imports.Is the only solution to have all optional dependencies (from which I import) installed when running Mypy?
The text was updated successfully, but these errors were encountered: