Skip to content

Commit 3d64f95

Browse files
committed
Clarified error messages in LazyTractogram
1 parent 1d27aef commit 3d64f95

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

nibabel/streamlines/tests/test_tractogram.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,8 @@ def test_lazy_tractogram_creation(self):
586586
# Creating LazyTractogram with generators is not allowed as
587587
# generators get exhausted and are not reusable unlike generator function.
588588
assert_raises(TypeError, LazyTractogram, streamlines)
589+
assert_raises(TypeError, LazyTractogram,
590+
data_per_point={"none": None})
589591
assert_raises(TypeError, LazyTractogram,
590592
data_per_streamline=data_per_streamline)
591593
assert_raises(TypeError, LazyTractogram, DATA['streamlines'],

nibabel/streamlines/tractogram.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,11 @@ def __getitem__(self, key):
165165
return self.store[key]()
166166

167167
def __setitem__(self, key, value):
168-
if value is not None and not callable(value): # TODO: why None?
169-
raise TypeError("`value` must be a generator function or None.")
168+
if not callable(value):
169+
msg = ("Values in a `LazyDict` must be generator functions."
170+
" Those are functions which whenever are called return an"
171+
" instantiated generator.")
172+
raise TypeError(msg)
170173
self.store[key] = value
171174

172175
def __delitem__(self, key):
@@ -604,7 +607,10 @@ def _apply_affine():
604607

605608
def _set_streamlines(self, value):
606609
if value is not None and not callable(value):
607-
raise TypeError("`streamlines` must be a generator function.")
610+
msg = ("`streamlines` must be a generator function. That is a"
611+
" function which whenever is called returns an"
612+
" instantiated generator.")
613+
raise TypeError(msg)
608614
self._streamlines = value
609615

610616
@property

0 commit comments

Comments
 (0)