I am building a library that automatically discovers remote API endpoints and populates an object with methods corresponding to the inferred endpoints. The dynamically created methods have the following structure:
def proxy(*args, **kwds):
# 1. Validate arguments: Do arguments match remote API?
# 2. Forward call to remote API
# 3. Parse and return response
pass
This works so far. However, I would like to set the method signature shown with help(proxy)
dynamically. It would increase the user interface greatly if users can see the inferred signatures directly and also use tab-completion for keyword arguments. Is there a way to decorate, annotate, or otherwise manipulate the function to achieve this?
The difference to Dynamically define functions with varying signature is that I only what to change the signature from the caller perspective. The definition of the method should be with *args
and **kwds
.