sphinx-contrib / napoleon

Other
148 stars 48 forks source link

Add example for property that returns generators #23

Closed erny closed 4 years ago

erny commented 4 years ago

It's said that properties docstrings should return type such as:

    @property
    def title(self):
        """str: document title"""
        return self._title

On the other hand, generators should use "Yields":

    def get_children(self):
        """Gets any contained elements

        Yields:
            Element: next contained document
        """
        for element in self._find_elements(parent=self.id):
            yield element

But how do we specify properties that return generators? Would this be correct?:

    @property
    def children(self):
        """:obj:`generator` of :obj:`Document`: contained elements"""
        for element in self._find_elements(parent=self.id):
            yield element
McSinyx commented 4 years ago

Hi, please note that this repo is deprecated. To answer to your question, by PEP 484, iterators should be typed as typing.Iterator[Document]. typing.Generator also exists but it has some extra functionalities.

erny commented 4 years ago

Thanks, I'll close this issue.