Skip to content

Clarified error messages in LazyTractogram #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions nibabel/streamlines/tests/test_tractogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
12 changes: 9 additions & 3 deletions nibabel/streamlines/tractogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

" function which, when called, returns an instantiated"
" generator.")
raise TypeError(msg)
self._streamlines = value

@property
Expand Down