Skip to content

Commit 34e3ce0

Browse files
committed
Improve typehints of xr.Dataset.__getitem__
Resolves #4125
1 parent 2a288f6 commit 34e3ce0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

xarray/core/dataset.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
TypeVar,
2828
Union,
2929
cast,
30+
overload,
3031
)
3132

3233
import numpy as np
@@ -1240,8 +1241,15 @@ def loc(self) -> _LocIndexer:
12401241
and only when the key is a dict of the form {dim: labels}.
12411242
"""
12421243
return _LocIndexer(self)
1244+
12431245

1244-
def __getitem__(self, key: Any) -> "Union[DataArray, Dataset]":
1246+
@overload
1247+
def __getitem__(self, key: Hashable) -> DataArray: ...
1248+
1249+
@overload
1250+
def __getitem__(self, key: Any) -> Dataset: ...
1251+
1252+
def __getitem__(self, key):
12451253
"""Access variables or coordinates this dataset as a
12461254
:py:class:`~xarray.DataArray`.
12471255

0 commit comments

Comments
 (0)