argh
argh copied to clipboard
partial objects as commands
Consider the following case:
import argh
from functools import partial
def _func1(data): ...
def _func2(data): ...
def dispatcher(func, data): func(data)
func1 = partial(dispatcher, _func1); func1.__name__ = "func1"
func2 = partial(dispatcher, _func2); func2.__name__ = "func2"
argh.dispatch_commands([func1, func2])
(Perhaps I don't want to call dispatch_command(dispatcher) and pass the choice of function as a string becase I want to define other completely different commands.)
This will fail because the partial objects have no __annotations__, even though inspect.signature will happily (and very reasonably) use the annotations of the wrapped function. (The partial objects also have no __name__ and for that there isn't really another choice that setting it explicitly.) It would be nice if argh did the same here, at least when inspect.signature is available.