pythondoxygen

Doxygen support for python decorators


is there any possibility to document functions whith the @property decorator using doxygen?

class someClass:
"""! @brief My Example Class """
    def __init__(self, name: str):
        self._name = name
        ## Name 2 is a public attribute.
        self.name2= "This is shown as expected..."

    @property
    def name(self):
    """! @brief Give the name or say Nobody. """
        if self._name == "":
            return "Nobody"
        return self._name

If I do this, name would be shown as a Public Member Function in the documentation (linke ToyTagger in this example picture). I think I should be shown under the Public Attributes section (linke name2). Yes, programmatically it is a function. But I use it like a class attribute...

The only thing I found was this feature request from 2022: https://github.com/doxygen/doxygen/issues/9315.

Is there any possibility to say, that name is a public class attribute? Thanks in advance, Jan


Solution

  • Yes, Doxygen doesn't natively recognize Python properties as attributes. There are three workarounds:

    1. Use the @property tag in your docstring:
    @property
    def name(self):
        """! @brief Give the name or say Nobody.
        @property
        """
        if self._name == "":
            return "Nobody"
        return self._name
    
    1. Document the underlying attribute instead:
    ## @var _name
    # Name attribute accessed through the name property
    
    1. Use Doxypy filter which has better Python property handling:
    FILTER_PATTERNS = *.py=doxypy
    

    None are perfect solutions. The GitHub issue you linked (#9315) remains open, indicating this limitation hasn't been fully addressed in Doxygen yet.