-
Notifications
You must be signed in to change notification settings - Fork 162
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
Typing: visit
not re-exported and partial/missing annotations
#1352
Comments
rustworkx.visit
visit
not re-exported and partial/missing annotations
I will post multiple comments but first things first.The missing re-export is a mistake. I will accept PRs to fix it or I will send one myself later. Notice that it is very easy to miss this kind of thing unfortunately, Also, thanks for continuously testing our library! I appreciate the issues. I know Qiskit uses the |
My second comment is regarding testing the stubs. This was surprisingly difficult in #401, you might find a couple commits trying to use https://github.com/davidfritzsche/pytest-mypy-testing which is the best tooling I found for the task. Most codebases organically get a good check because they run The I am open to adding |
Lastly, I assume when I originally wrote the annotations the implicit |
Qiskit not considering type annotations is another woe of mine. Regarding testing that the runtime types match the type annotations, I stumbled upon three types of tests:
An example using all these approaches is numpy: https://github.com/numpy/numpy/blob/main/numpy/typing/tests/test_typing.py What I had in mind is something different. Simply running |
I ran
It also found the missing return types in These are still mostly missing generic's parameters, but much less than before. This also shows that the different
The other few missing type annotations are:
The last two should definitely be fixed, while the first two will probably not be encountered since it's not common to explicitly call |
Information
I found two issues will using
rustworkx.visit
:visit
modules currently doesn't work for mypy for some reasonMore info:
The following python code doesn't pass mypy:
To solve this I suggest replacing in
rustworkx/__init__.pyi
the lineimport rustworkx.visit as visit
withfrom . import visit as visit
. This seems to fix the re-export locally for me. After the fix I only get the expectederror: Missing type parameters for generic type "BFSVisitor" [type-arg]
from running mypy on the script above (this type error is unavoidable until Allow some custom return types to be annotated as generic classes at runtime #1349 is addressed).Looking at
visit.pyi
I noticed that most of the methods do not have return type (should be-> None
). This raised a flag for me since I expectedrustworkx
's tests to catch partial typing. It seems thatstubtest
does not test for partial type hints - I tried running it and it did complain about several__all__
attributes missing in stubs but nothing else (rustworkx.generators.__all__
,rustworkx.rustworkx.__all__
,rustworkx.visualization.graphviz.__all__
andrustworkx.visualization.matplotlib.__all__
).However, if I run
mypy --strict -p rustworkx
I get a bunch of missing generic's parameters and some other type annotations. Either this orpyright --verifytypes rustworkx
catches also a lot of errors. I suggest adding one of these or both as a test(s) torustworkx
(and fixing the errors they emit).What is the current behavior?
visit
modules currently doesn't work for mypy for some reasonSteps to reproduce the problem
See above.
If my suggestions above sound good to you, I'm willing to open a PR and try implementing them.
PS, I really am using
BFSVisitor
, so this isn't just a continuation of my previous issue regarding generics.Thanks for responding and addressing, all my type-related issues so far. I know it might be petty of me since it doesn't change the runtime behavior by much, but I love using rustworkx and I love having my code type-checked.
The text was updated successfully, but these errors were encountered: