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

Decorated functions don't work through __wrapped__ when using argh.named or when using a namespace #132

Closed
kbrowder opened this issue Oct 5, 2018 · 2 comments

Comments

@kbrowder
Copy link

kbrowder commented Oct 5, 2018

import argh
import functools

def decorated(f):
    @functools.wraps(f)
    def wrapped(*args, **kwargs):
        print("Wrapping function call")
        return f(*args, **kwargs)
    return wrapped


def test1(a, b=1):
    print("Hello World!", a, b)

@decorated
def test2(a, b=1):
    print("Hello World!", a, b)

@argh.named("test4")
@decorated
@decorated
def test3(a, b=1):
    print("Hello World!", a, b)

parser = argh.ArghParser()
parser.add_commands([test1, test3])
parser.add_commands([test2], namespace='a')
argh.dispatch(parser)

Running --help on test4 or a test2 end up picking up the unwrapped variant, specifically they display optional positional arguments and no -b.

I guess this needs a similar solution to #111?

@kbrowder
Copy link
Author

kbrowder commented Oct 5, 2018

Hmmm, actually maybe I'm wrong, this seems to be more general, adding @decorated to test1 also results in incorrect argument parsing.

This is all in python 3.6.6

@kbrowder
Copy link
Author

kbrowder commented Oct 5, 2018

Oh never mind, I was assuming that the current release on pypi had fix #111 and PR #113, it does not. #124 encapsulates why.

@kbrowder kbrowder closed this as completed Oct 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant