-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Defining __getattr__ breaks _repr_html_ #2014
Comments
Ah, nevermind. I needed to raise |
Yep. To clarify, your |
Okay but what's the solution? |
If it checks for permissive attribute handling to mitigate potentially not having a |
So what is the resolution? I have the same issue |
In my def getattr(self, attr), I just did this:
to suppress that message. This is a hack I don't know any unintended consequence. For my case, I will post back if i see any weird behavior downstream. |
In general, your
Or at least have a broad refusal for e.g. anything that starts with an underscore:
Special-casing the 'canary' method defeats the point of it. IPython deliberately doesn't trust objects which claim to have an attribute with any name, because it can cause all sorts of problems if we call special methods which aren't really defined and do something unexpected. |
I created a class where I am storing rows of data with column headers. I want to display the contents in an HTML table in notebooks, so I'm using
_repr_html_
. I'd also like to access columns using the headers as attributes, likefoo.column1
. However, defining__getattr__
stops_repr_html_
from being called and the notebook falls back to__repr__
. This shouldn't happen because_repr_html_
is defined in the class instance, so__getattr__
shouldn't be called. I checked if__getattr__
is being called and it appears that_ipython_canary_method_should_not_exist_
is being called and then it falls back to the normal__repr__
.Here's an example:
The text was updated successfully, but these errors were encountered: