-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
MNT properly activate the env in the linting CI #17177
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
Conversation
A quick review @NicolasHug ? The azure linting job is not checking anything. |
sklearn/utils/tests/test_utils.py
Outdated
(np.float32("nan"), True), | ||
(np.float64("nan"), True), | ||
(np.float(float("nan")), True), | ||
(np.float32(float("nan")), True), |
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.
The signature of these functions is,
class float64(floating, builtins.float)
it does seem to work with strings, probably because float
is called on them internally, but technically that's not correct.
./build_tools/circle/linting.sh | ||
fi | ||
displayName: Run linting | ||
- bash: | | ||
set -ex |
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.
Print executed commands and exit on first failure.
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 @rth
I'm happy with the CI update, but I can't say I'm thrilled by the need to update some perfectly working code for mypy to be happy :/
Do we actually need the changes in the code, considering that mypy was working and running fine before?
# mypy error: Module 'sklearn.cluster' has no attribute '_hierarchical_fast' | ||
from . import _hierarchical_fast as _hierarchical # type: ignore |
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.
mypy doesn't like Cython files?
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.
Yeah, normally one currently has to write stub files for cython extensions since they don't expose annotations (see e.g. scipy/scipy#11936). I'm hoping this could be done automatically in the future though, since Cython should have all relevant information; possibly cython/cython#2552.
Edit: though actually maybe the issues with imports we are seeing are different. Could be worth investigating.
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.
When mypy
runs on the source (before anything is built), my understanding is that there is no way for mypy
to find the module. Is this correct?
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.
Yes, indeed. For most Cython imports errors will be ignored due to the --ignore-missing-import
flag, however not when importing whole modules for some reason,
python/mypy#8575 (comment)
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.
Also I'm getting these errors locally with scikit-learn correctly build. E.g. without this change,
$ mypy --ignore-missing-imports sklearn/cluster/_agglomerative.py
sklearn/cluster/_agglomerative.py:25: error: Module 'sklearn.cluster' has no attribute '_hierarchical_fast'
Found 1 err
8000
or in 1 file (checked 1 source file)
$ mypy --ignore-missing-imports sklearn
Success: no issues found in 599 source files
I don't really understand why the full run succeeds..
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 don't really understand why the full run succeeds..
Probably unrelated, but lately I've found that git diff upstream/master -u -- "*.py" | flake8 --diff
passes on some branches while build_tools/circle/linting.sh
(used by the CI) doesn't.
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.
Probably unrelated, but lately I've found that git diff upstream/master -u -- "*.py" | flake8 --diff passes on some branches while build_tools/circle/linting.sh (used by the CI) doesn't.
Yes, linting the diff has issues #11336 (comment) and I would like to start dealing with it once we are done with the release.
sklearn/utils/tests/test_utils.py
Outdated
(np.float("nan"), True), | ||
(np.float32("nan"), True), | ||
(np.float64("nan"), True), | ||
(np.float(float("nan")), True), |
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.
that makes me sad lol
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.
Remplaced with np.float64(np.nan)
which should be better, I think?
I know, running mypy on the full repo also worked fine. I had to make changes as I was getting errors with pre-commit (and the raised errors do make sense). |
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 have always been concerned with how much knowledge one needs to work around these mypy
linting errors. (One can see the mypy errors we are ignoring by greping for # mypy error
)
This PR is needed to get the linter to work. Thank you @rth !
Thanks @rth |
Fixes linting CI job on azure.
Currently it always returns a green status because the env fails to activate and the error is silenly ignored.The error on master is,
Originally fix added in #17053 see discussion there for more details.