@@ -196,6 +196,14 @@ def _get_click_type(
196196 raise TypeError (f'Unsupported CLI parameter type{ param_name } : { current !r} . Only primitive types are supported.' )
197197
198198
199+ def _get_class_annotation (click_type : Any ) -> type :
200+ # Classyclick inspects annotations at import time and expects a runtime type,
201+ # not typing.Any or a ParamType instance such as click.Path(...).
202+ if click_type is Any or isinstance (click_type , click .ParamType ):
203+ return str
204+ return click_type
205+
206+
199207def _iter_command_parameters (api_class : type , target_method : str ):
200208 signature = inspect .signature (getattr (api_class , target_method ))
201209
@@ -286,7 +294,7 @@ def __call__(self):
286294 }
287295
288296 for field_name , field , click_type , multiple , _converter in required_fields :
289- namespace ['__annotations__' ][field_name ] = click_type
297+ namespace ['__annotations__' ][field_name ] = _get_class_annotation ( click_type )
290298 option_kwargs = {
291299 'help' : _get_model_field_help (field ),
292300 'required' : True ,
@@ -306,7 +314,7 @@ def __call__(self):
306314 namespace ['__annotations__' ]['jq' ] = str
307315
308316 for field_name , field , click_type , multiple , _converter in optional_fields :
309- namespace ['__annotations__' ][field_name ] = click_type
317+ namespace ['__annotations__' ][field_name ] = _get_class_annotation ( click_type )
310318 option_kwargs = {
311319 'help' : _get_model_field_help (field ),
312320 'default' : field .default ,
@@ -519,7 +527,7 @@ def __call__(self):
519527
520528 for name , parameter , click_type , multiple , _converter in required_parameters :
521529 # required request-body models are passed as JSON strings and converted before the API call
522- namespace ['__annotations__' ][name ] = click_type
530+ namespace ['__annotations__' ][name ] = _get_class_annotation ( click_type )
523531 option_kwargs = {
524532 'help' : _get_help_from_annotation (parameter .annotation ),
525533 'required' : True ,
@@ -539,7 +547,7 @@ def __call__(self):
539547 namespace ['__annotations__' ]['jq' ] = str
540548
541549 for name , parameter , click_type , multiple , _converter in optional_parameters :
542- namespace ['__annotations__' ][name ] = click_type
550+ namespace ['__annotations__' ][name ] = _get_class_annotation ( click_type )
543551 option_kwargs = {
544552 'help' : _get_help_from_annotation (parameter .annotation ),
545553 'default' : parameter .default ,
0 commit comments