-
-
Notifications
You must be signed in to change notification settings - Fork 892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@wraps decorator to expose underlying method documentation #573
Conversation
@hsvlz the decorator does not wrap the original function, it returns the original function. Did you see a situation in which the documentation of the original function was lost? |
When iterating over socketio.server.handlers.items() in my function generating the documentation:
func ends up always being _handler with no access to func_name or func_docs. By adding this @wraps, I can access the underlying function information of a function using the decorator @socketio.on(...) |
Are you aware that |
Is there an alternative public way to iterate over function handlers, the same way it is safe to iterate over current_app.url_map.iter_rules() in flask? Otherwise, what do you propose in order to create auto-generated documentation of all socketio endpoints in realtime for a /documentation endpoint? |
No, there is currently no official way to iterate over the handlers. You could use a custom decorator to mark functions as needing documentation to avoid using the private attributes. |
The issue with adding custom decorators for documentation is:
@socketio.on() is guaranteed to be a decorator, therefore adding @wraps should not affect your implementation. I agree that your underlying implementation could evolve, and that both socketio.server and server.handlers are undocumented - I am using them at my own peril and should the implementation change, I would adapt. |
I'll think about this. It may make more sense to provide an iterator that can give you the actual functions, not the internal wrapper. |
That would work for me! Thank you Miguel. |
03a7df0
to
1fd43a3
Compare
@miguelgrinberg Has there been any progress on adding an iterator for handler functions? If not, would you be open to a pull request submission for it? I'm writing a sphinx plugin to generate documentation for Flask_SocketIO API endpoints, and it's proving to be impractical without a way to get at those original references. |
@bpengu1n I haven't done any work on this issue. Open to accept a contribution for it. Thanks! |
Hi Miguel,
adding a @wraps decorator to expose underlying method documentation for every socketio.on event