Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "_ipython_canary_method_should_not_exist_"?

I implemented my own __getattr__() to loosely handle any non-existent attributes.

I just so happened to define this class in a Jupyter notebook to experiment with it interactively.

IPython creates _ipython_canary_method_should_not_exist_ due to this __getattr__ implementation – and I'd like to understand what this is and how to "clean it up" is possible.

There is this issue opened about it, but it's not clear to my why – if it checks for permissive handling within __getattr__ – it doesn't check to see that _repr_html_ is implemented in the OP's example?

from types import SimpleNamespace

class Metabox(SimpleNamespace):

    def __getattr__(self, name):
        """
        Create a new namespace for any non-existing attributes.
        """
        print("calling __getattr__")
        self.__dict__[name] = Metabox()
        return self.__dict__[name]
like image 733
conner.xyz Avatar asked May 09 '19 22:05

conner.xyz


1 Answers

As taper mentioned in above comments; IPython sometimes needs to inspect objects to know whether they have some methods.

To handle object like yours; that always say "yes", when we have doubt we probe for this name; and if the object says "yep, I got that !" we know the object lies and implemented a __getattr__.

like image 72
Matt Avatar answered Nov 14 '22 08:11

Matt