-
Notifications
You must be signed in to change notification settings - Fork 268
More graceful handling of compressed file Opening #328
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
Changes from 5 commits
9875e1c
2f851a2
7410896
094f832
8da5d5c
3d2777e
f4c20f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,3 +146,17 @@ def __enter__(self): | |
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
self.close_if_mine() | ||
|
||
|
||
class ImageOpener(Opener): | ||
""" Opener-type class passed to image classes to collect compressed extensions | ||
""" | ||
@classmethod | ||
def register_ext_from_image(opener_klass, ext, func): | ||
"""Decorator""" | ||
def decorate(klass): | ||
assert ext not in opener_klass.compress_ext_map, \ | ||
"Cannot redefine extension-function mappings." | ||
opener_klass.compress_ext_map[ext] = func | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will modify the Opener class globally no? So all 'Opener' instances will now effectively become BinOpener instances? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly. The goal was to abstract I went this way because But perhaps I'm reading the code poorly... I was looking at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgive my anxiety here, but this decorator, though clever, makes me anxious. It's unexpected to me that a class decorator should alter the global state - in this case of attributes in another class. It makes it harder to reason about Can you see any way round that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, we only need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I believe that this depends what you mean "outside nibabel". If it imports But I feel I'm probably not understanding your concern properly.
I don't like this because each time a new extension is added, a new |
||
return klass | ||
return decorate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add note here on the lines of