Skip to content

Commit

Permalink
fix(typing): include ellipsis (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii authored Mar 16, 2021
1 parent 0369331 commit 4e1c461
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
====================

Version 2.2.1
--------------------

* Fix static typing with ellipses.
`#145 <https://github.com/scikit-hep/hist/pull/145>`_

Version 2.2.0
--------------------

Expand Down
12 changes: 8 additions & 4 deletions src/hist/basehist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...]]

Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/hist/namedhist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)

0 comments on commit 4e1c461

Please sign in to comment.