什么是“_ipython_canary_method_should_not_exist_”?

con*_*xyz 7 python ipython jupyter

我实现了自己的 __getattr__()的松散处理任何不存在的属性。

我碰巧在 Jupyter 笔记本中定义了这个类,以交互方式对其进行试验。

IPython_ipython_canary_method_should_not_exist_由于这种__getattr__实现而创建-我想了解这是什么以及如何“清理”它是可能的。

有一个关于它的问题,但我不清楚为什么 - 如果它检查内部的许可处理__getattr__- 它没有检查是否在 OP 的示例中实现了_repr_html_

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]
Run Code Online (Sandbox Code Playgroud)