使用 epydoc 记录公共全局函数

发布于 2024-09-09 07:17:24 字数 859 浏览 1 评论 0原文

我有一个包含多个全局函数和一个全局变量的模块。该变量和一些函数遵循 Python 的“私有”命名约定,名称前导下划线。其他函数旨在公开,并且没有前导下划线。

我在文件的开头声明了 __all__ 以及我的公共函数名称列表。

当尝试使用 epydoc 生成此模块的文档时,epydoc 正在考虑以下一切该模块为私有。而且,由于我使用 --no-private 标志,这意味着输出仅显示模块本身的文档,而不显示模块的元素或其单独的文档。

如果我不使用 epydoc 的 --no-private 标志,所有内容都会被记录下来。但我不想要那里的私人事物。关键在于:如果我注释掉我的 __all__,epydoc 会正确地仅记录我模块的公共元素。

我是一个相对的 Python 新手,但据我了解, __all__ 的目的是让您在导入其他模块然后其他模块导入您的模块时避免遇到麻烦,并在所有内容技术上都是公开的情况下尝试对事物进行更严格的限制,只要您知道您要访问的内容的名称。省略 __all__ 可能会导致 Bad Things™,至少有人告诉我。与此同时,epydoc 声称它尊重 __all__ 来决定什么是公开的、什么不是公开的。

是我错误地使用了 epydoc,错误地假设了代码中 __all__ 的使用,还是 epydoc 中的错误? (我已经解决了 epydoc 中的一个错误处理错误,该错误显然是由较新版本的 docutils 引起的。)

I have a module containing multiple global functions, and a global variable. The variable and some of the functions follow the 'private' naming convention for Python, with a leading underscore for the name. The other functions are intended to be public, and do not have a leading underscore.

I have declared __all__, with a list of my public function names, at the beginning of my file.

When trying to generate documentation for this module using epydoc, epydoc is considering everything in the module as private. And, since I'm using the --no-private flag, this means that the output only shows the documentation on the module itself, not the elements of the module or their individual documentation.

If I don't use the --no-private flag with epydoc, everything gets documented. But I don't want the private things there. Here's the kicker: If I comment out my __all__, epydoc correctly documents only the public elements of my module.

I'm a relative Python newbie, but as I understand it, __all__ is meant to keep you out of trouble when you import other modules and then other modules import yours, and for trying to keep a tighter lid on things when everything is technically public, so long as you know the name of what you're trying to access. Omitting __all__ can lead to Bad Things™, or so I'm told. At the same time, epydoc claims right and left that it honors __all__ for deciding what is public and what isn't.

Is it that I'm using epydoc wrong, assuming incorrectly about the usage of __all__ in my code, or a bug in epydoc? (I've already resolved one error handling bug in epydoc which is apparently caused by newer versions of docutils.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囍笑 2024-09-16 07:17:24

当使用 epydoc 记录多个文件时,这一问题就消失了。这似乎是 epydoc 中的一个错误,但只要您有一个实际的包来记录,而不是单个模块,它就很容易解决。

This problem disappears when using epydoc to document more than one file. It seems to be a bug in epydoc, but it's easily worked around, so long as you have an actual package to document, rather than a single module.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文