带元类的Sphinx自动类不工作

2024-06-17 08:16:45 发布

您现在位置:Python中文网/ 问答频道 /正文

元类:

class RequestMeta(type):
    def __new__(mcs, what, bases, attrs):
        _attrs = {name: decimal_to_string(attr) if callable(attr) else attr for name, attr in attrs.items()}
        return super().__new__(mcs, what, bases, _attrs)

当我们为元类导入RequestMeta时,Sphinx无法生成成员:

Class_name(metaclass=RequestMeta)
    def test
        """
        Get test
        :return:
        .. code-block:: json

            [
                {
                "message":"test",
                "timestamp": 123
                }
            ]
        """

test.rst:

Test
____

.. autoclass:: my_prog.a.Class_name
   :members:

1条回答
网友
1楼 · 发布于 2024-06-17 08:16:45

问题可能在于decimal_to_string装饰器。Sphinx不会关心元类,但是如果在装饰函数时去掉它的属性,那么它就无能为力了

检查decimal_to_string是否正在functools.wraps中包装其目标函数-这可能会解决您的问题

相关问题 更多 >