Skip to content

Conversation

wouterzwerink
Copy link

@wouterzwerink wouterzwerink commented Aug 2, 2025

Reviving #270 to make Typer treat keyword only parameters as options even when they dont have a default.

E.g.

@app.command()
def my_command(*, my_param):
     pass

Will now result in the following CLI with a required flag instead of positional parameter:
python my_module --my-param value

This is a breaking change, but I think it is the more logical behaviour. It allows people to get required options without default values in a really pythonic way that is much more intuitive than annotating type hints with typer.Option(...).

Supports #269

@wouterzwerink
Copy link
Author

I'm not sure where to add documentation for this, i.e. what the correct page would be. If anyone from the team could make a suggestion I'd be happy to document this.

@wouterzwerink wouterzwerink changed the title Treat keyword only parameters as OptionInfo even without default Treat keyword only parameters without defaults as option Aug 2, 2025
@wouterzwerink wouterzwerink changed the title Treat keyword only parameters without defaults as option ✨Treat keyword only parameters without defaults as option Aug 17, 2025
@YuriiMotov
Copy link

YuriiMotov commented Sep 22, 2025

@wouterzwerink, thanks for your interest!

I think the drawback of such approach is that it might break the existing code bases.
It's common do declare all parameters as keyword-only in order to avoid having to place parameters with defaults after parameters without defaults. This feature might break such code..

@app.command()
def hello(
    *,
    formal: bool = False,
    name: str,  #  <=  This will become option..
    color: str = "green",
):
    pass

#269 (comment)

Let's wait for Sebastian to approve the idea

@YuriiMotov YuriiMotov added the feature New feature, enhancement or request label Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature, enhancement or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants