Skip to content
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

partial objects as commands #80

Open
anntzer opened this issue Nov 13, 2014 · 0 comments
Open

partial objects as commands #80

anntzer opened this issue Nov 13, 2014 · 0 comments

Comments

@anntzer
Copy link

anntzer commented Nov 13, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants