Skip to content

Commit cbdfaa2

Browse files
authored
fix: avoid unnessary EH for control (#709)
1 parent 617fb4f commit cbdfaa2

File tree

1 file changed

+6
-7
lines changed
  • src/boost_histogram/_internal

1 file changed

+6
-7
lines changed

src/boost_histogram/_internal/hist.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -764,11 +764,10 @@ def __getitem__( # noqa: C901
764764

765765
# If this is (now) all integers, return the bin contents
766766
# But don't try *dict!
767-
if not hasattr(indexes, "items"):
768-
try:
769-
return self._hist.at(*indexes) # type: ignore[no-any-return]
770-
except RuntimeError:
771-
pass
767+
if not hasattr(indexes, "items") and all(
768+
isinstance(a, SupportsIndex) for a in indexes
769+
):
770+
return self._hist.at(*indexes) # type: ignore[no-any-return]
772771

773772
integrations: Set[int] = set()
774773
slices: List[_core.algorithm.reduce_command] = []
@@ -777,8 +776,8 @@ def __getitem__( # noqa: C901
777776

778777
# Compute needed slices and projections
779778
for i, ind in enumerate(indexes):
780-
if hasattr(ind, "__index__"):
781-
pick_each[i] = ind.__index__() + ( # type: ignore[union-attr]
779+
if isinstance(ind, SupportsIndex):
780+
pick_each[i] = ind.__index__() + (
782781
1 if self.axes[i].traits.underflow else 0
783782
)
784783
continue

0 commit comments

Comments
 (0)