neithere / argh

An argparse wrapper that doesn't make you say "argh" each time you deal with it.
http://argh.rtfd.org
GNU Lesser General Public License v3.0
369 stars 56 forks source link

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

Closed kbrowder closed 6 years ago

kbrowder commented 6 years ago
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 commented 6 years ago

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 commented 6 years ago

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