-
Notifications
You must be signed in to change notification settings - Fork 102
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
Unparameterized np.ndarray
typings produce "Type of ... is partially unknown" Pyright type errors.
#309
Comments
np.ndarray
typings produce "Type of ... is partially unknown" Pyright type errors.np.ndarray
typings produce "Type of ... is partially unknown" Pyright type errors.
Two other things:
I've also tried: PythonScalar = str | int | float | bool
ArrayLike = numpy.typing.ArrayLike
MatrixLike = numpy.typing.NDArray[PythonScalar] | pd.DataFrame | spmatrix But this also produces unknown types in _ScalarType_co = TypeVar("_ScalarType_co", bound=generic, covariant=True) # <-- this bit
_DType = TypeVar("_DType", bound=dtype[Any])
_DType_co = TypeVar("_DType_co", covariant=True, bound=dtype[Any])
NDArray = ndarray[Any, dtype[_ScalarType_co]] So, |
When I change MatrixLike = np.ndarray[object, object] | pd.DataFrame | spmatrix Pylance gives me a diagnostic on the second type argument:
How about using MatrixLike = np.ndarray[Any, Any] | pd.DataFrame | spmatrix Feel free to submit a PR. |
we might need better documentation for these errors? (https://microsoft.github.io/pyright/#/configuration?id=type-check-diagnostics-settings)
this doc might help to understand about these errors |
Problem
The type
np.ndarray
is stubbed in this library as:Throughout these stubs, the type
np.ndarray
is used without provided type parameters, seemingly with the expectation that this is treated asnp.ndarray[Any, Any]
(or more properlynp.ndarray[object. object]
). However, Pyright in strict mode alternately interprets this asnp.ndarray[Unknown, Unknown]
.As a result, every method that involves
np.ndarray
or a type alias which includes it produces a partially-unknown-type error:Example Reproduction
For example, if we take the following simple file
example.py
...In this case, the error occurs because the type of
fit
is:And in turn
MatrixLike
is a (private) typealias that resolves to:Resolution
At least for this example, changing that type alias as follows resolves the type error.
System Details:
OS: MacOS Sonoma 14.1.2
Python: CPython 3.12.1
Pyright: 1.1.358
Pyright configuration:
The text was updated successfully, but these errors were encountered: