Skip to content

Treat keyword only parameters without defaults as option #1267

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant