在 Python 模块上子类化 __dir__

问题描述

从 Python 3.7 开始,可以在模块上定义 __dir__()。但是,如果您想获取 dir(module) 的“正常”输出并从中添加或删除,该怎么办?

例如,我想做这样的事情:

def __dir__():
    dir_out = super().__dir__()[:]  # does not work
    dir_out.pop('Optional')  # get rid of the typing imports
    return dir_out

显然因为模块不是普通类,所以 super() 调用不起作用。但是还有别的方法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)