-
-
Notifications
You must be signed in to change notification settings - Fork 12k
TYP: Remove None from definition of DTypeLike type alias
#29739
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
Conversation
|
We could do a little experiment and try to see what mypy_primer will report when we remove |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Hmm, I expected worse. It's mostly xarray that's affected by this it seems. |
DTypeLike | None fixNone from definition of DTypeLike type alias
None from definition of DTypeLike type aliasNone from definition of DTypeLike type alias
|
Yup. And even then, it looks manageable IMHO this would be an acceptable change, but it's your decision of course |
|
Since there's no way to deprecate this, there's no painless way of doing this, so I'm inclined to agree. |
jorenham
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are also some None-less DTypeLike's in _core.numerictypes
|
sure, i've added it to |
|
The |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Joren Hammudoglu <[email protected]>
This comment has been minimized.
This comment has been minimized.
|
Ok the xarray PR has been merged, so it should be gone from the next mypy_primer run. Also, it's probably a good idea to put this in the release notes. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Joren Hammudoglu <[email protected]>
|
Diff from mypy_primer, showing the effect of this PR on type check results on a corpus of open source code: xarray (https://github.com/pydata/xarray)
- xarray/compat/npcompat.py:54: note: def isdtype(dtype: dtype[Any] | type, kind: type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None | tuple[type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None, ...]) -> bool
+ xarray/compat/npcompat.py:54: note: def isdtype(dtype: dtype[Any] | type, kind: type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | tuple[type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str, ...]) -> bool
- xarray/compat/npcompat.py:54: note: def isdtype(dtype: dtype[Any] | type[Any], kind: type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None | tuple[type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None, ...]) -> bool
+ xarray/compat/npcompat.py:54: note: def isdtype(dtype: dtype[Any] | type[Any], kind: type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | tuple[type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str, ...]) -> bool
pandera (https://github.com/pandera-dev/pandera)
- pandera/engines/numpy_engine.py:60: error: Item "_SupportsDType[dtype[Any]]" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None" has no attribute "type" [union-attr]
+ pandera/engines/numpy_engine.py:60: error: Item "_SupportsDType[dtype[Any]]" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str" has no attribute "type" [union-attr]
- pandera/engines/numpy_engine.py:60: error: Item "tuple[Any, ...]" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None" has no attribute "type" [union-attr]
+ pandera/engines/numpy_engine.py:60: error: Item "tuple[Any, ...]" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str" has no attribute "type" [union-attr]
- pandera/engines/numpy_engine.py:60: error: Item "list[Any]" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None" has no attribute "type" [union-attr]
+ pandera/engines/numpy_engine.py:60: error: Item "list[Any]" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str" has no attribute "type" [union-attr]
- pandera/engines/numpy_engine.py:60: error: Item "_DTypeDict" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None" has no attribute "type" [union-attr]
+ pandera/engines/numpy_engine.py:60: error: Item "_DTypeDict" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str" has no attribute "type" [union-attr]
- pandera/engines/numpy_engine.py:60: error: Item "str" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None" has no attribute "type" [union-attr]
+ pandera/engines/numpy_engine.py:60: error: Item "str" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str" has no attribute "type" [union-attr]
- pandera/engines/numpy_engine.py:60: error: Item "None" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None" has no attribute "type" [union-attr]
- pandera/engines/numpy_engine.py:77: error: Item "_SupportsDType[dtype[Any]]" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None" has no attribute "name" [union-attr]
+ pandera/engines/numpy_engine.py:77: error: Item "_SupportsDType[dtype[Any]]" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str" has no attribute "name" [union-attr]
- pandera/engines/numpy_engine.py:77: error: Item "tuple[Any, ...]" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None" has no attribute "name" [union-attr]
+ pandera/engines/numpy_engine.py:77: error: Item "tuple[Any, ...]" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str" has no attribute "name" [union-attr]
- pandera/engines/numpy_engine.py:77: error: Item "list[Any]" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None" has no attribute "name" [union-attr]
+ pandera/engines/numpy_engine.py:77: error: Item "list[Any]" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str" has no attribute "name" [union-attr]
- pandera/engines/numpy_engine.py:77: error: Item "_DTypeDict" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None" has no attribute "name" [union-attr]
+ pandera/engines/numpy_engine.py:77: error: Item "_DTypeDict" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str" has no attribute "name" [union-attr]
- pandera/engines/numpy_engine.py:77: error: Item "str" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None" has no attribute "name" [union-attr]
+ pandera/engines/numpy_engine.py:77: error: Item "str" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str" has no attribute "name" [union-attr]
- pandera/engines/numpy_engine.py:77: error: Item "None" of "type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None" has no attribute "name" [union-attr]
spark (https://github.com/apache/spark)
- python/pyspark/pandas/frame.py:11229: error: Argument 1 to "is_bool_dtype" has incompatible type "pyspark.pandas.series.Series[Any]"; expected "ExtensionArray | ndarray[tuple[Any, ...], dtype[Any]] | type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | None | pandas.core.series.Series[Any] | DataFrame | Index[Any] | ExtensionDtype" [arg-type]
+ python/pyspark/pandas/frame.py:11229: error: Argument 1 to "is_bool_dtype" has incompatible type "pyspark.pandas.series.Series[Any]"; expected "ExtensionArray | ndarray[tuple[Any, ...], dtype[Any]] | type[Any] | dtype[Any] | _SupportsDType[dtype[Any]] | tuple[Any, Any] | list[Any] | _DTypeDict | str | pandas.core.series.Series[Any] | DataFrame | Index[Any] | ExtensionDtype" [arg-type]
|
|
In it goes... Thanks Marco; great QOL improvement! |
…py#29739) Co-authored-by: Joren Hammudoglu <[email protected]>
…py#29739) Co-authored-by: Joren Hammudoglu <[email protected]>
…py#29739) Co-authored-by: Joren Hammudoglu <[email protected]>
Addressing #29634 (comment)
I haven't removed
| NonefromDTypeLike, as it's a publicly exported type and so changing it would be a breaking change, and I didn't know if that would be OKNote that there are some places which currently accept
dtype: DTypeLike, even thoughNonecannot be passed. For example,isdtype:numpy/numpy/_core/numerictypes.pyi
Line 157 in 9c29c32
It says
DTypeLike, which includesNone, althoughNoneis not valid at runtimeAnyway, I've left such cases alone