-
Notifications
You must be signed in to change notification settings - Fork 189
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
Add minimal 'mypy' run to the pre-commit hooks. #4176
Conversation
Yeh but you know we can't add these proper type annotations, until we drop python 3.5 support in October: https://devguide.python.org/#status-of-python-branches |
These are only method argument and return value annotations, which is supported by Python 3.5. We just cannot add variable annotations because that was only added in Python 3.6. Anyway, I really cannot wait for |
Only variable annotations and lazy annotations are not supported, right? Need to fix the lazy thing, though.. |
Ah fair enough brilliant, for some reason I thought it was 3.5, otherwise I would have already added them! |
75f85e1
to
eb7701d
Compare
Well the other big thing in the pipeline is TypedDict (introduced in 3.8). Having worked with interfaces in TypeScript, which are similar, these will be so helpful. Other than that LGTM 👍 |
@chrisjsewell just changed something more: |
Ah, and def walk_nodes(self, filters=None, node_class=None, query_batch=None) -> Iterable[WalkNodeResult]: to def walk_nodes(self, filters=None, node_class=None, query_batch=None) -> Iterator[WalkNodeResult]: |
1e96327
to
2e1451b
Compare
Codecov Report
@@ Coverage Diff @@
## develop #4176 +/- ##
===========================================
+ Coverage 78.94% 78.94% +0.01%
===========================================
Files 467 467
Lines 34501 34510 +9
===========================================
+ Hits 27232 27242 +10
+ Misses 7269 7268 -1
Continue to review full report at Codecov.
|
2e1451b
to
a27f94c
Compare
Is this a known flaky test? |
73af1c7
to
1024b59
Compare
I haven't seen it fail yet, but it is relatively new. This looks like it comes from a test that was put in to check the REST API cleanly closing the SqlAlchemy sessions so we don't get a timeout because the queuepool is exhausted. Clearly this was triggered here where we run with reduced pool size and overflow, but don't see how your changes should have affected it. So I would just chalk this up to bad luck for now and ignore it until we start to see it more often |
BTW, I have just been reading up on a 2-year long discussion on |
1024b59
to
ab8b494
Compare
FYI, there is a potential for confusion because our In my own packages I solved this by import typing as ty
<...>
ty.Dict I'm open for better suggestions, but since this is a problem that's bound to happen in many places in our code base, it's probably a good idea to have a consistent style. Should probably be changed in |
Currently, only two files are checked: aiida/tools/groups/paths.py and aiida/engine/processes/calcjobs/calcjob.py. The option 'follow_imports' is set to 'skip', because there are a lot of issues in other files, mostly because these lack type hints. From here, we can continue expanding the type hints one file at a time: - add the file to 'files' in the 'mypy' pre-commit hook - fix all issues that mypy reports Co-authored-by: Chris Sewell <[email protected]>
ab8b494
to
a896fe3
Compare
; Strictness settings | ||
; disallow_any_unimported = True | ||
; disallow_any_expr = True | ||
; disallow_any_decorated = True | ||
; disallow_any_explicit = True | ||
; disallow_any_generics = True | ||
; disallow_subclassing_any = True | ||
|
||
; disallow_untyped_calls = True | ||
; disallow_untyped_defs = True | ||
; disallow_incomplete_defs = True | ||
; disallow_untyped_decorators = True | ||
|
||
; no_implicit_optional = True | ||
; no_strict_optional = False | ||
|
||
; Enable all warnings | ||
; warn_redundant_casts = True | ||
; warn_unused_ignores = True | ||
; warn_return_any = True | ||
; warn_unreachable = True | ||
|
||
; allow_untyped_globals = False | ||
; strict_equality = 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.
can we get rid of all these if we are not using them?
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, although it might be nice seeing them listed here since (I think) the goal would be to slowly enable some of them.
ignore_missing_imports = True | ||
|
||
[mypy-plumpy.*] | ||
ignore_missing_imports = 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.
Is this similar to pylint
issuing missing import warnings if it is not being run in the "system" environment? If so, would it make sense to also run mypy
under system?
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.. has its own "import system" - the problem here is that when dependencies don't have type annotations, that will be reported as a failure.
For now I'm not sure this makes a difference since we also use skip
for the follow_imports
option, but we definitely want to get rid of that one eventually.
The import mechanism is described here: https://mypy.readthedocs.io/en/stable/running_mypy.html#how-mypy-handles-imports
Thanks @greschd |
Currently, only two files are checked:
aiida/tools/groups/paths.py
andaiida/engine/processes/calcjobs/calcjob.py
. The optionfollow_imports
is set toskip
, because there are a lot of issues in other files, mostly because these lack type hints.Even on the two checked files, the strictness level of mypy is minimal (see the commented options in
mypy.ini
).From here, we can continue expanding the type hints one file at
a time:
files
in themypy
pre-commit hook@chrisjsewell I had to change some of the type hints in
groups/paths.py
- please check that these are correct.