Incorrect type warning on numpy load file parameter
PyCharm 2023.1 (Professional Edition)
I am loading a numpy array from a binary file, as follows:
import numpy as np
with open('test.npy', 'rb') as f:
arr = np.load(f)
PyCharm highlights the f with a message "Expected type 'str', got 'BinaryIO' instead".
If you hover over the load, it shows the definition as:
def load(file: str, ...
So the warning is consistent with that definition.
However, if I press Cmd-B on load to look at the actual source code for load(), the header is:
def load(file, ...
Where is PyCharm finding the definition that has the file parameter as a string only? I have tried updating numpy to the latest version (1.24) and invalidating the caches. The same problem occurs with save()
Thanks,
Julian
Please sign in to leave a comment.
Hi, Thank you for reporting this. I'm not sure how PyCharm infers the parameter type in this case, but I submitted a bug report https://youtrack.jetbrains.com/issue/PY-60224/Incorrect-type-is-inferred-for-numpy.load
Thanks very much. I've added a comment to the bug report to add some more detail.
Julian