From 70d3cf6a991158095ad56cbc9642a52c15ee92d9 Mon Sep 17 00:00:00 2001
From: Tamas Gal <tgal@km3net.de>
Date: Fri, 11 Dec 2020 23:33:09 +0100
Subject: [PATCH] Deactivate iteration which was not implemented anyways

---
 km3io/rootio.py       | 7 +++++++
 tests/test_offline.py | 4 ++++
 2 files changed, 11 insertions(+)

diff --git a/km3io/rootio.py b/km3io/rootio.py
index 56a7fec..186fe5e 100644
--- a/km3io/rootio.py
+++ b/km3io/rootio.py
@@ -354,6 +354,13 @@ class Branch:
 
         return unfold_indices(self._branch[key].array(), self._index_chain)
 
+    def __iter__(self):
+        raise NotImplementedError(
+            "iterating over a nested branch is not supported nor recommended. "
+            "If you really feel you need to do it, open an issue in "
+            "https://git.km3net.de/km3py/km3io"
+        )
+
     def __getitem__(self, key):
         return self.__class__(
             self._branch, self.fields, self._aliases, self._index_chain + [key]
diff --git a/tests/test_offline.py b/tests/test_offline.py
index 84d0cb6..9c11402 100644
--- a/tests/test_offline.py
+++ b/tests/test_offline.py
@@ -235,6 +235,10 @@ class TestOfflineEvents(unittest.TestCase):
         with self.assertRaises(NotImplementedError):
             [e.id for e in self.events[2:8][2:4]]
 
+    def test_iteration_over_subbranches_raises(self):
+        with self.assertRaises(NotImplementedError):
+            [t for t in self.events[0].tracks]
+
     def test_str(self):
         assert str(self.n_events) in str(self.events)
 
-- 
GitLab