python - 为什么 __all__ 应该只包含字符串对象?

标签 python pylint

今天我遇到了以下pylint错误:

invalid-all-object (E0604):

Invalid object %r in __all__, must contain only strings Used when an invalid (non-string) object occurs in __all__.

我很好奇为什么直接公开对象被认为是不正确的?

最佳答案

因为它应该是名称的列表,而不是值:

If the list of identifiers is replaced by a star ('*'), all public names defined in the module are bound in the local namespace for the scope where the import statement occurs.

The public names defined by a module are determined by checking the module’s namespace for a variable named __all__; if defined, it must be a sequence of strings which are names defined or imported by that module. The names given in __all__ are all considered public and are required to exist. If __all__ is not defined, the set of public names includes all names found in the module’s namespace which do not begin with an underscore character ('_'). __all__ should contain the entire public API. It is intended to avoid accidentally exporting items that are not part of the API (such as library modules which were imported and used within the module). [Language Reference]

关于python - 为什么 __all__ 应该只包含字符串对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41860105/

相关文章:

python - 在 Linux (CentOS) 的 Python 中及时获取负载或获取更短时间段的 getloadavg()

python - 如何从所服务的 TensorFlow 模型获取元数据?

python - 在 Python 中 reshape 数据(列表/数组)

python - dateutilrelativedelta(weekday=FR) 是否有等效的月份?

python - 如何为 argparse 参数提供类型提示?

python - pyreverse 不绘制关系/箭头/连接

python - 在 Ipython 中使用 Pylint(Jupyter-Notebook)

python - 如何使程序停止并从最低到最大打印输入?

python - 如何打破 .pylintrc 文件中的长行?

python - Pylint - Pylint 无法导入 flask.ext.wtf?