readthedocs / sphinx-autoapi

A new approach to API documentation in Sphinx.
https://sphinx-autoapi.readthedocs.io/
MIT License
415 stars 126 forks source link

Parses first element of if __name__ == '__main__' block #429

Open jsatuit opened 3 months ago

jsatuit commented 3 months ago

If a module has an if __name__ == '__main__: block, the first element is analysed and its documentation is generated. The next ones are ignored. This is regardless if it the first a variable or a function.

Uses python 3.11, sphinx-autoapi 3.0.0, Sphinx 7.2.6

I expect the behaviour to be that everything in if __name__ == '__main__: blocks would be ignored like sphinx-autodoc does.

Minimal working example: Analysing

def normal_function():
    """
    Function with docstring
    """
    pass

if __name__ == '__main__':
    def new_example():
        """
        This function will appear in the docs
        """
        pass
    this_variable_is_ignored = 52

gives

IV50eJKtYclZcZur

When variable is first, this appears in the docs while the function new_example is ignored.