clize icon indicating copy to clipboard operation
clize copied to clipboard

@argument_decorator decorated functions are not reusable

Open ramnes opened this issue 6 years ago • 1 comments

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:

  • either calling one function from the other, which doesn't work because the function signature is modified;
@argument_decorator
def foo(bar):
    return bar

@argument_decorator
def baz(qux):
    return foo(qux)
  • or by reusing the other as an argument, à la pytest fixtures fashion, which doesn't seem implemented.
@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?

ramnes avatar Dec 12 '17 11:12 ramnes

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

epsy avatar Dec 12 '17 15:12 epsy