diff --git a/nibabel/streamlines/tests/test_tractogram.py b/nibabel/streamlines/tests/test_tractogram.py index d21e88e0f3..cfa62793b0 100644 --- a/nibabel/streamlines/tests/test_tractogram.py +++ b/nibabel/streamlines/tests/test_tractogram.py @@ -586,6 +586,8 @@ def test_lazy_tractogram_creation(self): # Creating LazyTractogram with generators is not allowed as # generators get exhausted and are not reusable unlike generator function. assert_raises(TypeError, LazyTractogram, streamlines) + assert_raises(TypeError, LazyTractogram, + data_per_point={"none": None}) assert_raises(TypeError, LazyTractogram, data_per_streamline=data_per_streamline) assert_raises(TypeError, LazyTractogram, DATA['streamlines'], diff --git a/nibabel/streamlines/tractogram.py b/nibabel/streamlines/tractogram.py index b386f27fa5..40b1c3aea7 100644 --- a/nibabel/streamlines/tractogram.py +++ b/nibabel/streamlines/tractogram.py @@ -165,8 +165,11 @@ def __getitem__(self, key): return self.store[key]() def __setitem__(self, key, value): - if value is not None and not callable(value): # TODO: why None? - raise TypeError("`value` must be a generator function or None.") + if not callable(value): + msg = ("Values in a `LazyDict` must be generator functions." + " These are functions which, when called, return an" + " instantiated generator.") + raise TypeError(msg) self.store[key] = value def __delitem__(self, key): @@ -604,7 +607,10 @@ def _apply_affine(): def _set_streamlines(self, value): if value is not None and not callable(value): - raise TypeError("`streamlines` must be a generator function.") + msg = ("`streamlines` must be a generator function. That is a" + " function which, when called, returns an instantiated" + " generator.") + raise TypeError(msg) self._streamlines = value @property