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: Overloaded return types with np.cross NoReturn leads to type-checking issues #22146

Closed
danielpmorton opened this issue Aug 17, 2022 · 9 comments · Fixed by #22359
Closed

Comments

@danielpmorton
Copy link

Describe the issue:

np.cross appears to have a return type of NoReturn when dealing with _ArrayLikeBool_co type, and this NoReturn type is incompatible with type checking in Pylance, and VSCode determines that all code after a call to np.cross is unreachable.

This has been mentioned in a Pylance issue here (microsoft/pylance-release#3195), but they recommended mentioning it with NumPy.

Reproduce the code example:

import numpy as np

x = np.array([1,2,3])
y = np.array([2,3,4])

z = np.cross(x, y)
# This code is determined as unreachable by VSCode due to a NoReturn type
print(z)

Error message:

No response

NumPy/Python version information:

1.23.2 3.9.12 (main, Jun 12 2022, 13:39:05)
[GCC 9.4.0]

Context for the issue:

My code uses np.cross in many places, as well as extensive type-checking. It would be very nice if the return types could be cleaned up to improve compatibility with VSCode/Pylance/Pyright, because right now all of my code is grayed-out

@LeonaTaric
Copy link
Contributor

image
in the code, only type ArrayLikeBool will noreturn, ArrayLikeInt or ArrayLikeFloat will return type Array correctly

@wzy-99
Copy link

wzy-99 commented Aug 25, 2022

I have the same problem, and i just commented out the NoReturn function.

@nimagitac
Copy link

I have also the same problem. Pylance marked some lines as unreachable. (The temporary remedy could be the usage of "dtype" in numpy.cross function)

@danielpmorton
Copy link
Author

Yeah, I would prefer to not have to manually modify my own installation of NumPy to adjust this, and this should be a relatively quick fix for the development team

@wolfrayet
Copy link

I also have the same problem. I cannot solve it even if I specify the array type.

iantra added a commit to iantra/numpy that referenced this issue Sep 1, 2022
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
iantra added a commit to iantra/numpy that referenced this issue Sep 1, 2022
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 pushed a commit to charris/numpy that referenced this issue Sep 7, 2022
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
@ShapingView
Copy link

Reopen this issue?

--> #22359 (comment)

@Liquidmasl
Copy link

this issue returned. for a while now.
please re open the issue!

@mattip
Copy link
Member

mattip commented Jan 31, 2024

@Liquidmasl please tell us a bit more: how are you seeing this? Is it exactly like in the original description? What version of NumPy are you using?

@Liquidmasl
Copy link

Liquidmasl commented Jan 31, 2024

EDIT: I just found this issue: #24999
sorryyy
will leave rest of comment for another lost developer like me...

@Liquidmasl please tell us a bit more: how are you seeing this? Is it exactly like in the original description? What version of NumPy are you using?

i use 1.36.3
I do not use pylance but pycharm, but the issue is (i believe) the same.
although you did make me less sure about it

Screenshot 2024-01-31 185613

when checking the overloads there is this one overload:

@overload
def cross(
    a: _ArrayLikeBool_co,
    b: _ArrayLikeBool_co,
    axisa: int = ...,
    axisb: int = ...,
    axisc: int = ...,
    axis: None | int = ...,
) -> NoReturn: ...

which seams to be the issue. although i dont quite understand why the arrays are assumed to be dtype bool

even declaring dtypes on the input arrays does not help
image

But maybe this is a completely different issue?

maybe i should comment there? #22359 (comment)

(sorry i am somewhat new to the open source world.)

EDIT: I just found this issue: #24999

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants