0

I'm trying to use sphinx autodoc to generate documentation for my python project. I can't seem to be able to preserve the docstring in this code:

class aps_sio():
    def __init__(self, server, port, mav, is_sim=False): 
        ########## ASYNC IO INITIALIZATION ##########
        # creates a new Async Socket IO Server
        #sio = socketio.AsyncServer()
        self.server = server
        self.port = port
        self.sio = socketio.AsyncServer(async_mode='aiohttp')
        self.mav = mav
        # Creates a new Aiohttp Web Application
        self.app = web.Application()
        # Binds our Socket.IO server to our Web App
        # instance
        self.sio.attach(self.app)

        #############################################

        # Note: these decorated functions are created at initialization time, thus are indented with __init__

        @self.sio.on('connect')
        async def on_connect(sid, environ): 
            """Event handler for an socket.io connection. Logs the connection and adds the SID to the sid_list

            :param sid: The unique socket ID of the requesting connection
            :type sid: string
            :param environ: Enviroment object for the requesting connection
            :type environ: Enviroment Object
            """
            self.sid_list.append(sid)
            self.logger.log_aps('%s - Socket Connected, SID: %s IP: %s' % (time.time(), sid, environ['REMOTE_ADDR']))

if __name__ == "__main__":
   sio1 = aps_sio("localhost",8005, mav1)

I'm at a loss on how to use something like functool.wraps like the accepted answer in this question: Python decorator handling docstrings

How would I go about preserving the function docstring?

Thanks

MjBVala
  • 137
  • 3
  • 9
  • Is this a top-level function, or an inner function? Where is `self` defined? I think you need to show more of your code, the `self` use in the decorator is very strange. – Miguel Grinberg Feb 20 '20 at 12:51
  • I've added more code with some comments to show the full problem. The decorator is an event handler with the socket.io package: https://python-socketio.readthedocs.io/en/latest/client.html – MjBVala Feb 20 '20 at 19:13
  • I'm not sure if it is possible to do this. Here is a similar question about a non-decorated function: https://stackoverflow.com/q/12039633/407651. – mzjn Feb 21 '20 at 16:07
  • Why would a user of your class need to know the details of the nested `on_connect` function? Can the user really affect it in any way? And where are `self.sid_list` and `self.logger` defined? – mzjn Feb 22 '20 at 06:50
  • The idea is for any student working on this project to have a thorough source of documentation, hence full coverage. Otherwise yeah it wouldn't matter. Those two are defined in a seperate module and imported into this one, since it is out of the scope of the problem I didn't bring the contents of that module in. – MjBVala Feb 24 '20 at 18:19

0 Answers0