From 4b2b5f28653dcf0bd5921bdced7be0a8ae86f451 Mon Sep 17 00:00:00 2001 From: bahtya Date: Thu, 9 Apr 2026 03:18:25 +0800 Subject: [PATCH] fix: guard default value comparison against types with strict __eq__ Fixes #3298. When a non-string default value (e.g. semver.Version) is used with an option, Click help text builder compares it against an empty string using ==. Types that implement __eq__ to only accept specific types will raise a ValueError. Add an isinstance(default_value, str) guard before the equality check so non-string types fall through to str(default_value) instead. --- src/click/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/click/core.py b/src/click/core.py index f0a624be3..6dc44f399 100644 --- a/src/click/core.py +++ b/src/click/core.py @@ -3110,7 +3110,7 @@ def get_help_extra(self, ctx: Context) -> types.OptionHelpExtra: )[1] elif self.is_bool_flag and not self.secondary_opts and not default_value: default_string = "" - elif default_value == "": + elif isinstance(default_value, str) and default_value == "": default_string = '""' else: default_string = str(default_value)