-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix type annotations for get_axis_num
(GH 9822)
#9827
Conversation
Explicitly annotate that a single `str` argument leads to an `int` return, overriding the match against Iterable.
Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient. |
Hmm, seems mypy isn't liking that in CI, although it didn't complain when I used it to verify my MCVE. I'll investigate and re-open when I've figured out why. |
Ok, the mypy error is explained in more detail here. The problem is that when passing a variable that's statically known to be So I've done the pragmatic thing and just suppressed the mypy error. The documentation linked above says
|
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.
Would it not be enough to reverse the order of the existing overloads?
Or will that mess up tuples (which are hashable)?
I haven't tested it, but I assume you'd run into that problem. |
Thanks a lot for the contribution @bmerry ! Would it be possible to add a test function which uses these? If the test function is annotated with |
If I have time I'll give it a go, but to be honest I'm not sure I will. The test itself should be fairly easy to write, but setting up a test environment will have a learning curve since I've not used conda before and I don't want to risk it getting into a fight with pyenv over my PYTHON_PATH. |
Yeah that's fair. Being able to make small contributions is important, and I think this is a good enough win that it's worth merging. If you manage to set up an environment feel free to add a test to immortalize your contribution! (and I use pip to avoid the overhead, you might find it easier...) |
That sounds good. What arguments are you passing to pip to install all the right dependencies? |
|
Try |
Explicitly annotate that a single
str
argument leads to anint
return, overriding the match against Iterable.whats-new.rst
I haven't added tests since I didn't spot any existing tests of type annotations, but let me know if I missed them.