From 004e65edf6be1eb4f71e365e274f23bd08780f55 Mon Sep 17 00:00:00 2001 From: Hiren Date: Mon, 23 Feb 2026 23:07:32 -0500 Subject: [PATCH] fix: show full Optional[T] type in help instead of just Optional Use repr() instead of __qualname__ to get full type representation. Fixes google/python-fire#508 --- fire/helptext.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/fire/helptext.py b/fire/helptext.py index 347278da..6c237120 100644 --- a/fire/helptext.py +++ b/fire/helptext.py @@ -524,13 +524,9 @@ def _GetArgType(arg, spec): """ if arg in spec.annotations: arg_type = spec.annotations[arg] - try: - return arg_type.__qualname__ - except AttributeError: - # Some typing objects, such as typing.Union do not have either a __name__ - # or __qualname__ attribute. - # repr(typing.Union[int, str]) will return ': typing.Union[int, str]' - return repr(arg_type) + # Use repr() to get full type representation including generic args (e.g., Optional[str]) + # This fixes the bug where __qualname__ returns just "Optional" instead of "Optional[str]" + return repr(arg_type) return ''