File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -50,3 +50,32 @@ def main() -> None:
5050
5151 assert result .exit_code == 0
5252 assert "Show this message" in result .stdout
53+
54+
55+ def test_rich_doesnt_print_None_default ():
56+ app = typer .Typer (rich_markup_mode = "rich" )
57+
58+ @app .command ()
59+ def main (
60+ name : str ,
61+ option_1 : str = typer .Option (
62+ "option_1_default" ,
63+ ),
64+ option_2 : str = typer .Option (
65+ ...,
66+ ),
67+ ):
68+ print (f"Hello { name } " )
69+ print (f"First: { option_1 } " )
70+ print (f"Second: { option_2 } " )
71+
72+ result = runner .invoke (app , ["--help" ])
73+ assert "Usage" in result .stdout
74+ assert "name" in result .stdout
75+ assert "option-1" in result .stdout
76+ assert "option-2" in result .stdout
77+ assert result .stdout .count ("[default: None]" ) == 0
78+ result = runner .invoke (app , ["Rick" , "--option-2=Morty" ])
79+ assert "Hello Rick" in result .stdout
80+ assert "First: option_1_default" in result .stdout
81+ assert "Second: Morty" in result .stdout
Original file line number Diff line number Diff line change @@ -288,9 +288,11 @@ def _get_parameter_help(
288288 # Default value
289289 # This uses Typer's specific param._get_default_string
290290 if isinstance (param , (TyperOption , TyperArgument )):
291- if param .show_default :
292- show_default_is_str = isinstance (param .show_default , str )
293- default_value = param ._extract_default_help_str (ctx = ctx )
291+ default_value = param ._extract_default_help_str (ctx = ctx )
292+ show_default_is_str = isinstance (param .show_default , str )
293+ if show_default_is_str or (
294+ default_value is not None and (param .show_default or ctx .show_default )
295+ ):
294296 default_str = param ._get_default_string (
295297 ctx = ctx ,
296298 show_default_is_str = show_default_is_str ,
You canβt perform that action at this time.
0 commit comments