This repository was archived by the owner on Jun 10, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 32
Type error with np.dtype
#42
Comments
person142
added a commit
to person142/scipy
that referenced
this issue
Mar 20, 2020
One error appears to be an issue in the NumPy stubs: numpy/numpy-stubs#42 The other is fixed by modifying how we import `linalg_version` inside the linalg setup.
This was referenced Mar 20, 2020
person142
added a commit
to person142/numpy-stubs
that referenced
this issue
Mar 21, 2020
Closes numpy#42. `np.dtype` accepts a wide variety of lists as dtypes, some examples include: - `[('R', 'u1'), ('G', np.unicode_, 1)]` - `[('R', 'u1', (2, 2)), ('G', np.unicode_, 1)]` Without further hints mypy is going to type those as `List[object]`, so precise hints will require that users add annotations. In addition, typing the above is challenging because the inputs have to be a list, which is invariant, so you can't use `Union`s inside the list to reduce the number of cases. Work around that by just accepting `List[Any]`.
shoyer
pushed a commit
that referenced
this issue
Mar 24, 2020
Closes #42. `np.dtype` accepts a wide variety of lists as dtypes, some examples include: - `[('R', 'u1'), ('G', np.unicode_, 1)]` - `[('R', 'u1', (2, 2)), ('G', np.unicode_, 1)]` Without further hints mypy is going to type those as `List[object]`, so precise hints will require that users add annotations. In addition, typing the above is challenging because the inputs have to be a list, which is invariant, so you can't use `Union`s inside the list to reduce the number of cases. Work around that by just accepting `List[Any]`.
person142
added a commit
to person142/scipy
that referenced
this issue
Mar 25, 2020
Now that numpy/numpy-stubs#42 is resolved we can remove an ignore from `test_mio.py`.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Minimal reproducer
Running mypy on the following code:
Results in the following error:
Note that putting
object_dtype
on the previous line is important; otherwise the context of the function signature:https://mypy.readthedocs.io/en/latest/type_inference_and_annotations.html#context-in-type-inference
will broaden the type to
List[Tuple[str, Any]]
(I think.)Context
Stumbled across this while working on typing in SciPy, with the current version of the NumPy stubs there's an error because of this line:
https://github.com/scipy/scipy/blob/master/scipy/io/matlab/tests/test_mio.py#L140
Speculation
I think this is happening because
List
is invariant andobject
is a subtype ofAny
, so despite the fact that_DtypeLikeNested
is typed as any here:https://github.com/numpy/numpy-stubs/blob/master/numpy-stubs/__init__.pyi#L41
object
still isn't let through here:https://github.com/numpy/numpy-stubs/blob/master/numpy-stubs/__init__.pyi#L61
The text was updated successfully, but these errors were encountered: