From 4e1c4610ebda671bae9b971825eda018972a5ca3 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 16 Mar 2021 18:45:02 -0400 Subject: [PATCH] fix(typing): include ellipsis (#145) --- docs/changelog.rst | 6 ++++++ src/hist/basehist.py | 12 ++++++++---- src/hist/namedhist.py | 8 ++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 527c14a0..c85c5fcf 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,12 @@ Changelog ==================== +Version 2.2.1 +-------------------- + +* Fix static typing with ellipses. + `#145 `_ + Version 2.2.0 -------------------- diff --git a/src/hist/basehist.py b/src/hist/basehist.py index 64d8bf67..a5c3a93d 100644 --- a/src/hist/basehist.py +++ b/src/hist/basehist.py @@ -30,10 +30,14 @@ from .typing import ArrayLike, SupportsIndex if TYPE_CHECKING: + from builtins import ellipsis + import matplotlib.axes from mplhep.plot import Hist1DArtists, Hist2DArtists -InnerIndexing = Union[SupportsIndex, str, Callable[[bh.axis.Axis], int], slice] +InnerIndexing = Union[ + SupportsIndex, str, Callable[[bh.axis.Axis], int], slice, "ellipsis" +] IndexingWithMapping = Union[InnerIndexing, Mapping[Union[int, str], InnerIndexing]] IndexingExpr = Union[IndexingWithMapping, Tuple[IndexingWithMapping, ...]] @@ -99,7 +103,7 @@ def __init__( ax.label = f"Axis {i}" if data is not None: - self[...] = data # type: ignore + self[...] = data def _generate_axes_(self) -> NamedAxesTuple: """ @@ -261,7 +265,7 @@ def _index_transform(self, index: IndexingExpr) -> bh.IndexingExpr: return tuple(self._loc_shortcut(v) for v in index) # type: ignore def __getitem__( # type: ignore - self: T, index: SupportsIndex + self: T, index: IndexingExpr ) -> Union[T, float, bh.accumulators.Accumulator]: """ Get histogram item. @@ -270,7 +274,7 @@ def __getitem__( # type: ignore return super().__getitem__(self._index_transform(index)) def __setitem__( # type: ignore - self, index: SupportsIndex, value: Union[ArrayLike, bh.accumulators.Accumulator] + self, index: IndexingExpr, value: Union[ArrayLike, bh.accumulators.Accumulator] ) -> None: """ Set histogram item. diff --git a/src/hist/namedhist.py b/src/hist/namedhist.py index fb262c97..9af19e8a 100644 --- a/src/hist/namedhist.py +++ b/src/hist/namedhist.py @@ -73,12 +73,12 @@ def __getitem__( # type: ignore f"Only access by names are supported for {self.__class__.__name__} in dictionay" ) - return super().__getitem__(index) # type: ignore + return super().__getitem__(index) def __setitem__( # type: ignore - self: T, + self, index: IndexingExpr, - value: Union[T, ArrayLike, bh.accumulators.Accumulator], + value: Union[ArrayLike, bh.accumulators.Accumulator], ) -> None: """ Set histogram item. @@ -90,4 +90,4 @@ def __setitem__( # type: ignore f"Only access by names are supported for {self.__class__.__name__} in dictionay" ) - return super().__setitem__(index, value) # type: ignore + return super().__setitem__(index, value)