Skip to content
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

BUG: change overloads to play nice with pyright. #22220

Merged
merged 2 commits into from Sep 7, 2022

Conversation

charris
Copy link
Member

@charris charris commented Sep 7, 2022

Backport of #22193.

It seems Pyright just chooses the first matching type whenever there is ambiguity in type resolution, which leads to a NoReturn for numpy.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 for numpy.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.

Pyright just chooses the first matching type whenever there is ambiguity in type resolution, which leads to NoReturn for the cross function in certain situations. Other overloads were changed to match. See ticket numpy#22146
@charris charris added this to the 1.23.3 release milestone Sep 7, 2022
@charris charris merged commit bf46295 into numpy:maintenance/1.23.x Sep 7, 2022
@charris charris deleted the backport-22193 branch September 7, 2022 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants