-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
Confusing error from hv.opts prior to hv.extension() #5463
Comments
A way to get a better message is with a metaclass: import param
from param.parameterized import ParameterizedMetaclass
class OptsMeta(ParameterizedMetaclass):
def __getattr__(self, attr):
try:
return super().__getattr__(attr)
except AttributeError:
msg = f"No subobject of type {attr} has been registered; maybe you need to run 'hv.extension' to declare a plotting backend?"
raise AttributeError(msg) from None
class opts(param.ParameterizedFunction, metaclass=OptsMeta):
pass |
Sounds good to me! @jlstevens ? |
Yes, I like this metaclass approach! The message is good but wouldn't it appear for other missing attributes, e.g. due to typos ( I think a better message might be:
Would be happy to merge a PR using this approach/message. |
Good point; sounds good. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Current published and master versions of HoloViews give a bewildering error when trying to create element-specific options objects:
hv.opts apparently only populates its various accessors when hv.extension loads, but the error message doesn't convey anything to me about "run hv.extension()". I've encountered this issue several times over the years, usually when I'm trying to isolate some code that (in my mind) has nothing to do with a particular backend. Each time I get completely sidetracked -- I'm trying to debug one thing, and now suddenly I can't even set an option on hv.opts.Image? It's particularly a problem in a Jupyter notebook, when I restart the kernel, then try to look at a tiny bit of code that has nothing to do with actual plotting, and suddenly things like this don't work. Eventually I do figure out that it's because hv.extension needs to be run, but each time I've now wasted a good bit of time.
Is there a way that instead of failing with this obscure message, instead it could print something helpful, like "No subobject of type Image has been registered; maybe you need to run hv.extension to declare a plotting backend?"?
The text was updated successfully, but these errors were encountered: