argh icon indicating copy to clipboard operation
argh copied to clipboard

partial objects as commands

Open anntzer opened this issue 11 years ago • 0 comments

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.

anntzer avatar Nov 13 '14 22:11 anntzer