[Python] click.option with deprecated=str failed with unexpected keyword argument

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    Here is short sample, which uses click==8.1.7

    # main.py
    import click


    @click.command
    @click.option(
    "--disable-all",
    is_flag=True,
    default=False,
    deprecated="Please use --disable-all-features",
    )
    @click.option("--disable-all-features", is_flag=True, default=False)
    def main(disable_all, disable_all_features):
    print(f"{disable_all=}")
    print(f"{disable_all_features=}")


    if __name__ == "__main__":
    main()


    When I run this, I got the following error:

    Traceback (most recent call last):
    File "/home/xxx/sandbox/click-option-alias/main.py", line 12, in <module>
    def main(disable_all, disable_all_features):
    File "/home/xxx/sandbox/click-option-alias/.venv/lib/python3.9/site-packages/click/decorators.py", line 373, in decorator
    _param_memo(f, cls(param_decls, **attrs))
    File "/home/xxx/sandbox/click-option-alias/.venv/lib/python3.9/site-packages/click/core.py", line 2536, in __init__
    super().__init__(param_decls, type=type, multiple=multiple, **attrs)
    TypeError: __init__() got an unexpected keyword argument 'deprecated'


    How do I make the deprecation feature work?

    Continue reading...

Compartilhe esta Página