1

I decorate my functions wit @click.command and @click.option to give command line access to the function.

But how can I then run the original function?

import click


@click.command("user-info")
@click.option("--name")
def print_user_info(name: str):
    print(f"info for {name}")


if __name__ == "__main__":
    print_user_info(name="john")

gives a type error:

TypeError: init() got an unexpected keyword argument 'name'

EDIT: A workaround would be to add another function inside of the wrapped function:

def print_user_info(name: str):
    print(f"info for {name}")


@click.command("user-info")
@click.option("--name")
def print_user_info_click(name: str):
    print_user_info(name=name)
Leevi L
  • 1,538
  • 2
  • 13
  • 28
  • Does this answer your question? [here](https://stackoverflow.com/questions/1166118/how-to-strip-decorators-from-a-function-in-python) Someone mentioned a `__wrapped__` attribute. – NotSirius-A May 08 '21 at 12:44
  • the `__wrapped__` attribute might be part of functools or some other package, but a function decorated with `click.command` and `click.option` does not have a `__wrapped__` attribute. Trying to access it raises an `AttributeError`: `AttributeError: 'Command' object has no attribute '__wrapped__'` – Leevi L May 08 '21 at 13:04

0 Answers0