@@ -76,13 +76,19 @@ class ArgparseArg:
7676 id : str
7777 arg : Arg
7878 type : Optional [Union [Type , Callable [[str ], Any ]]] = None
79+ orig_type : Optional [Union [Type , Callable [[str ], Any ]]] = None
7980 default : Any = DEFAULT_PLACEHOLDER
8081 # We modify the help to add types so we store it twice to store old and new
8182 help : Optional [str ] = None
8283 action : Optional [Union [str , Type [argparse .Action ]]] = None
8384 choices : Optional [Union [List [str ], List [Enum ]]] = None
8485 has_converter : bool = False
8586
87+ @property
88+ def display_type (self ) -> Optional [Union [Type , Callable [[str ], Any ]]]:
89+ default_type = self .type if self .type is not None else self .orig_type
90+ return self .orig_type if self .has_converter else default_type
91+
8692 def to_argparse (self ) -> Tuple [List [str ], Dict [str , Any ]]:
8793 """Helper method to generate args and kwargs for Parser.add_argument."""
8894 args : List [str ] = []
@@ -112,13 +118,20 @@ def get_arg(
112118 orig_arg : Arg ,
113119 param_type : Any ,
114120 * ,
121+ orig_type : Optional [Union [Type , Callable [[str ], Any ]]] = None ,
115122 default : Optional [Any ] = DEFAULT_PLACEHOLDER ,
116123 get_converter : Optional [Callable [[Type ], Optional [ConverterType ]]] = None ,
117124 skip_resolve : bool = False ,
118125) -> ArgparseArg :
119126 """Generate an argument to add to argparse and interpret types if possible."""
120- arg = ArgparseArg (id = param , arg = orig_arg , type = param_type , help = orig_arg .help )
121- arg .default = default
127+ arg = ArgparseArg (
128+ id = param ,
129+ arg = orig_arg ,
130+ type = param_type ,
131+ help = orig_arg .help ,
132+ default = default ,
133+ orig_type = orig_type ,
134+ )
122135 if orig_arg .count :
123136 arg .action = "count"
124137 arg .type = None
0 commit comments