Skip to content

Commit

Permalink
Add comments on when to use which TypeVar
Browse files Browse the repository at this point in the history
From the chars of pydata#8208
  • Loading branch information
max-sixty committed Sep 19, 2023
1 parent 2b444af commit 89e816e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion xarray/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,15 @@ def copy(

T_DataArrayOrSet = TypeVar("T_DataArrayOrSet", bound=Union["Dataset", "DataArray"])

# Maybe we rename this to T_Data or something less Fortran-y?
# Use `T_Xarray` for most functions, when the return type matches the input type — for
# example `ds.where(cond)` returns a `Dataset` when `ds` is a `Dataset`, and
# `da.where(cond)` returns a `DataArray` when `da` is a `DataArray`.
T_Xarray = TypeVar("T_Xarray", "DataArray", "Dataset")

# Use `T_DataWithCoords` for:
# - functions that return either `DataArray` or `Dataset`, and
# we're not sure which one it will be
# - directly with `DataWithCoords`
T_DataWithCoords = TypeVar("T_DataWithCoords", bound="DataWithCoords")
T_Alignable = TypeVar("T_Alignable", bound="Alignable")

Expand Down

0 comments on commit 89e816e

Please sign in to comment.