Python 压制;“基类继承的方法”;在子类docstring中

Python 压制;“基类继承的方法”;在子类docstring中,python,inheritance,ipython,docstring,Python,Inheritance,Ipython,Docstring,我正在用大量方法和长docstring对一个类进行子类化。如果调用IPython帮助函数,我会看到原始类的所有帮助。 我想这是意料之中的,有没有办法抑制这种情况?我只想看到我重新定义的方法 mymodule.py是: import matplotlib.axes class MySubclass(matplotlib.axes.Axes): pass 如果我在IPython这样做: import mymodule help(mymodule) 打印输出非常庞大,因为它包含所有“从ma

我正在用大量方法和长docstring对一个类进行子类化。如果调用IPython帮助函数,我会看到原始类的所有帮助。 我想这是意料之中的,有没有办法抑制这种情况?我只想看到我重新定义的方法

mymodule.py
是:

import matplotlib.axes
class MySubclass(matplotlib.axes.Axes):
    pass
如果我在IPython这样做:

import mymodule
help(mymodule)

打印输出非常庞大,因为它包含所有“从matplotlib.axes继承的方法。\u axes.axes:”这是兆字节的文本,因为它列出了类中所有方法的docstring。

我能想到的唯一方法是,如果将基类中定义的所有函数都放在子类中,并在其中创建自己的docstring,那么它们就可以被覆盖。您甚至可以保留空白的docstring,不管您喜欢什么,但这将是非常不切实际的。

如前所述,一个可行的解决方案是手动删除文档

## List the methods from the original class
method_list = [func for func in dir(mymodule.MySubclass) if \ 
  callable(getattr(mymodule.MySubclass, func))]

## Remove doc for methods
for func in method_list:
  ## Change only original user defined methods
  if ("_" not in el[0:2]):
    original_method = getattr(mymodule.MySubclass, func)
    setattr(original_method, "__doc__", "")
  else:
    pass

这可以很容易地封装在装饰器中,并在实例化子类或导入模块时调用。

您是在询问您的
MySubclass
类是否可以抑制该输出,还是询问是否有方法使用
help
函数而不查看该输出,还是其他方法?第一种方法更好,但是即使是第二个也会很有趣,即使只是一些关于这方面的见解也会很有趣,你确认这是预期的吗?它是Python还是IPython特性?它不是IPython特性;
help
功能是内置的。我认为不可能抑制这种输出。您所能做的最好的事情可能是编写您自己的
help
函数。。。