sphinx-autoapi icon indicating copy to clipboard operation
sphinx-autoapi copied to clipboard

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

Open jsatuit opened this issue 10 months ago • 0 comments

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.

jsatuit avatar Apr 03 '24 04:04 jsatuit