From b2234d9f0439d973953bae4d9b0266351a352ddb Mon Sep 17 00:00:00 2001 From: Matthew Messinger Date: Tue, 14 Jan 2025 13:30:49 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20default=20value=20hand?= =?UTF-8?q?ling=20in=20parameter=20help=20extraction=20when=20rich=20is=20?= =?UTF-8?q?installed=20Fixes=20#465?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improves consitency with typer/core.py TyperArgument.get_help_record, which does not print the default value if it is None. --- typer/rich_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/typer/rich_utils.py b/typer/rich_utils.py index 7d603da2d7..46e2474ea7 100644 --- a/typer/rich_utils.py +++ b/typer/rich_utils.py @@ -285,9 +285,9 @@ def _get_parameter_help( # Default value # This uses Typer's specific param._get_default_string if isinstance(param, (TyperOption, TyperArgument)): - if param.show_default: - show_default_is_str = isinstance(param.show_default, str) - default_value = param._extract_default_help_str(ctx=ctx) + default_value = param._extract_default_help_str(ctx=ctx) + show_default_is_str = isinstance(param.show_default, str) + if show_default_is_str or (default_value is not None and (param.show_default or ctx.show_default)): default_str = param._get_default_string( ctx=ctx, show_default_is_str=show_default_is_str, From 5b8aa86bc54c6681aae64ed0c6c27e40da4bbc57 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 Jan 2025 18:35:44 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20for?= =?UTF-8?q?mat=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typer/rich_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/typer/rich_utils.py b/typer/rich_utils.py index 46e2474ea7..a563ddd2bf 100644 --- a/typer/rich_utils.py +++ b/typer/rich_utils.py @@ -287,7 +287,9 @@ def _get_parameter_help( if isinstance(param, (TyperOption, TyperArgument)): default_value = param._extract_default_help_str(ctx=ctx) show_default_is_str = isinstance(param.show_default, str) - if show_default_is_str or (default_value is not None and (param.show_default or ctx.show_default)): + if show_default_is_str or ( + default_value is not None and (param.show_default or ctx.show_default) + ): default_str = param._get_default_string( ctx=ctx, show_default_is_str=show_default_is_str,