简体   繁体   English

Python:如何使用装饰器向 function 添加 doxygen 注释?

[英]Python: How can I add a doxygen comment to a function with a decorator?

Where do I have to insert the doxygen comment?:我必须在哪里插入 doxygen 注释?:

 ##
 # @brief Text
 @classmethod
 def foo(self):
     pass

or like this:或者像这样:

 @classmethod
 ##
 # @brief Text
 def foo(self):
     pass

Docstrings are preferred when documenting functions and classes in Python. Fortunately, Doxygen supports this way of documenting as well.在 Python 中记录函数和类时首选文档字符串。幸运的是,Doxygen 也支持这种记录方式。 To do so, simply use an exclamation mark !为此,只需使用感叹号! at the start of your docstring.在文档字符串的开头。

from dataclasses import dataclass


@dataclass(init=False)
class SomeClass:
    """!
    @brief ...
    @details ...
    """
    _name: str   #<! ...
    _amount: int #<! ...

    def __init__(self, name: str, amount: int) -> None:
        """!
        @brief ...
        @details ...
        @param[in] name ...
        @param[in] amount ...
        """
        self._name = name
        self._amount = amount

    @property
    def name(self) -> str:
        """!
        @brief ...
        @return ...
        """
        return self._name

    @property
    def amount(self) -> int:
        """!
        @brief ...
        @return ...
        """
        return self._amount

    @amount.setter
    def amount(self, value: int) -> None:
        """!
        @brief ...
        @param[in] value ...
        """
        self._amount = value

    @staticmethod
    def addone(arg: int) -> int:
        """!
        @brief ...
        @details ...
        @param[in] arg ...
        @return ...
        """
        return arg + 1

When I have:当我有:

    def __init__(self, name: str, amount: int) -> None:
        """
        @brief ...
        @details ...
        @param[in] name ...
        @param[in] amount ...
        """
        self._name = name
        self._amount = amount

and

PYTHON_DOCSTRING = YES

this results in the documentation:这导致文档:

在此处输入图像描述

When using使用时

PYTHON_DOCSTRING = NO

this results in:这导致:

在此处输入图像描述

which is the same as when using """! .这与使用"""!时相同。

Tested with: 1.9.4 (5d15657a55555e6181a7830a5c723af75e7577e2)测试:1.9.4(5d15657a55555e6181a7830a5c723af75e7577e2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM