BUG: change overloads to play nice with pyright. #22220
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #22193.
It seems Pyright just chooses the first matching type whenever there is ambiguity in type resolution, which leads to a
NoReturn
fornumpy.cross
in certain situations (See #22146.) As far as I can tell, there is no agreed-upon behavior or guidelines for dealing with ambiguity in type resolution, so this is valid behavior on Pyright's side (see microsoft/pyright#2521 for a discussion on this topic.)I suppose the ideal solution would be to resolve the ambiguity, but AFAIK there is no way to do that for constructs like
numpy.array([1, 2, 3])
on the numpy side, short of asking every user to include a dtype in these cases. I would love to be proven wrong though.I think the second best solution is to have the more general overload also be the first one that matches, so that we make as few assumptions as possible about what might happen inside the function when given an
NDArray[Any]
. The other overloads were just changed so that they match the one fornumpy.cross
.I would also consider changing the overload order in functions elsewhere in the library, if it makes sense.
I am very open to suggestions if someone has a better idea on how to deal with this.