You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using mypy to check my code, I'm getting a spurious error. When passing a single string to get_axis_num, the return type is determined to be tuple[int, ...] instead of int.
What did you expect to happen?
I expected the return type to be int when passing a single single.
Minimal Complete Verifiable Example
# Note: to be run through mypyimportxarrayasxrdeffoo(x: xr.DataArray) ->None:
reveal_type(x.get_axis_num("time"))
MVCE confirmation
Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
Complete example — the example is self-contained, including all data and the text of any traceback.
Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
New issue — a search of GitHub Issues suggests this is not a duplicate.
Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
# Output from mypytest.py:4: note: Revealedtypeis"builtins.tuple[builtins.int, ...]"Success: noissuesfoundin1sourcefile
Anything else we need to know?
From a quick look at the code, I'm guessing this is because str is iterable and so is matching the first @overload.
Thanks for opening your first issue here at xarray! Be sure to follow the issue template!
If you have an idea for a solution, we would really welcome a Pull Request with proposed changes.
See the Contributing Guide for more.
It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better.
Thank you!
What happened?
When using mypy to check my code, I'm getting a spurious error. When passing a single string to
get_axis_num
, the return type is determined to betuple[int, ...]
instead ofint
.What did you expect to happen?
I expected the return type to be
int
when passing a single single.Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
From a quick look at the code, I'm guessing this is because
str
is iterable and so is matching the first@overload
.Environment
INSTALLED VERSIONS
commit: None
python: 3.12.3 (main, Nov 6 2024, 18:32:19) [GCC 13.2.0]
python-bits: 64
OS: Linux
OS-release: 6.8.0-49-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: ('C', 'UTF-8')
libhdf5: 1.14.2
libnetcdf: None
xarray: 2024.11.0
pandas: 2.1.4
numpy: 1.26.2
scipy: 1.11.4
netCDF4: None
pydap: None
h5netcdf: None
h5py: 3.11.0
zarr: None
cftime: None
nc_time_axis: None
iris: None
bottleneck: None
dask: 2023.12.0
distributed: None
matplotlib: 3.9.1
cartopy: None
seaborn: None
numbagg: None
fsspec: 2023.12.1
cupy: 13.2.0
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 75.1.0
pip: 24.3.1
conda: None
pytest: 8.2.2
mypy: 1.11.1
IPython: 8.18.1
sphinx: 7.2.6
The text was updated successfully, but these errors were encountered: