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

@argument_decorator decorated functions are not reusable #32

Open
ramnes opened this issue Dec 12, 2017 · 1 comment
Open

@argument_decorator decorated functions are not reusable #32

ramnes opened this issue Dec 12, 2017 · 1 comment

Comments

@ramnes
Copy link

ramnes commented Dec 12, 2017

Salut @epsy. 👋

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?

@epsy
Copy link
Owner

epsy commented Dec 12, 2017

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

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