Skip to content

Conversation

mattmess1221
Copy link
Contributor

@mattmess1221 mattmess1221 commented Jan 14, 2025

Related to #465

Improves consistency with Typer(rich_markup_mode=None) (TyperArgument.get_help_record), which does not print the default value if it is None.

mattmess1221 and others added 2 commits January 14, 2025 13:30
…s installed

Fixes fastapi#465

Improves consitency with typer/core.py TyperArgument.get_help_record, which does not print the default value if it is None.
@svlandeg svlandeg added the bug Something isn't working label Jan 15, 2025
Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR @mattmess1221! I'll put this on my queue to review in detail and will get back to you 🙏

@svlandeg svlandeg self-assigned this Mar 13, 2025
Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this, @mattmess1221!

It's true that in Rich mode, the help text prints [default: None] which is unhelpful, because the argument is still required and the default effectively useless.

When printing the help without Rich, these None defaults are suppressed with the code in core.py as you referenced:

typer/typer/core.py

Lines 351 to 355 in 74e0923

show_default_is_str = isinstance(self.show_default, str)
if show_default_is_str or (
default_value is not None and (self.show_default or ctx.show_default)
):

It makes sense to ensure the same behaviour whether or not we're printing with Rich, and for clarity I agree to copy the structure from core.py into rich_utils.py. This also means adding the check for ctx.show_default which seems to have been missing previously.

I'll leave this to Tiangolo for a final review.

Thanks again!

@svlandeg svlandeg changed the title 🐛 Fix default value handling in parameter help extraction when rich is installed 🐛 Avoid printing default: None in the help section when using Rich Aug 22, 2025
@svlandeg svlandeg removed their assignment Aug 22, 2025
Copy link
Member

@tiangolo tiangolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you! 🚀

And thanks for the review @svlandeg 🙌

This will be available in Typer 0.17.2 in the next minutes. 🤓

@tiangolo tiangolo enabled auto-merge (squash) August 30, 2025 12:09
@tiangolo tiangolo merged commit cdc29e2 into fastapi:master Aug 30, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants