aiorpc
aiorpc copied to clipboard
Way to enforce argument types and optional arguments
I think it would be awesome if there was a way to define what kind of input a function takes, if it's required, and a way to enforce the type (i.e. str, int). Of the top of my head, we could do something like this:
@aiorpc.method({
'id': [str, True],
'ttl': [int, False, 86400]
})
async def set_ttl(payload):
...
All decorated functions would be registered as methods, and the provided dict would list the name of the arguments, and then the value would be a list- Type, Required, Default (optional). On the backend we could implement our own validation logic or build json schema objects on the fly.
I see two advantages:
- A way to abstract away from the requirement of implementing validation logic inside each function.
- We can have optional arguments in methods (which is always cool)
Thoughts?