epsy / clize

CLIze: Turn Python functions into command-line interfaces
http://clize.readthedocs.io/
MIT License
478 stars 26 forks source link

@argument_decorator decorated functions are not reusable #32

Open ramnes opened 6 years ago

ramnes commented 6 years ago

Salut @epsy. :wave:

It seems that if you have two @argument_decorator decorated functions and want to use one inside the other, it's currently impossible.

Intuitively, I'd have expected it to work by:

@argument_decorator
def foo(bar):
    return bar

@argument_decorator
def baz(qux):
    return foo(qux)
@argument_decorator
def foo(bar):
    return bar

@argument_decorator
def baz(qux: foo):
    return qux

What's your recommandation on this? Would you see yourself implement one of those two examples?

epsy commented 6 years ago

Your second method would indeed be how it should work.

As it is currently, argument decorators flat out ignore anything indicated on their first parameter, because it is entirely determined by the parameter that was originally annotated:

# clize never looks at this
@argument_decorator
def level_2(arg, b):
    ...

# `arg`'s annotation is ignored
@argument_decorator
def level_1(arg: level_2, a):
    ...

# The specifics of `param` (e.g. it being an option/named parameter) completely override anything supplied by `level_1`.
def main(*, param: level_1):
    ...

I'll see if some special handling can be done for argument_decorator, else this will have to wait until #24