@@ -196,6 +196,15 @@ 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+ if click_type is Any :
202+ return str
203+ if isinstance (click_type , click .Path ):
204+ return Path
205+ return click_type
206+
207+
199208def _iter_command_parameters (api_class : type , target_method : str ):
200209 signature = inspect .signature (getattr (api_class , target_method ))
201210
@@ -286,7 +295,7 @@ def __call__(self):
286295 }
287296
288297 for field_name , field , click_type , multiple , _converter in required_fields :
289- namespace ['__annotations__' ][field_name ] = click_type
298+ namespace ['__annotations__' ][field_name ] = _get_class_annotation ( click_type )
290299 option_kwargs = {
291300 'help' : _get_model_field_help (field ),
292301 'required' : True ,
@@ -306,7 +315,7 @@ def __call__(self):
306315 namespace ['__annotations__' ]['jq' ] = str
307316
308317 for field_name , field , click_type , multiple , _converter in optional_fields :
309- namespace ['__annotations__' ][field_name ] = click_type
318+ namespace ['__annotations__' ][field_name ] = _get_class_annotation ( click_type )
310319 option_kwargs = {
311320 'help' : _get_model_field_help (field ),
312321 'default' : field .default ,
@@ -519,7 +528,7 @@ def __call__(self):
519528
520529 for name , parameter , click_type , multiple , _converter in required_parameters :
521530 # required request-body models are passed as JSON strings and converted before the API call
522- namespace ['__annotations__' ][name ] = click_type
531+ namespace ['__annotations__' ][name ] = _get_class_annotation ( click_type )
523532 option_kwargs = {
524533 'help' : _get_help_from_annotation (parameter .annotation ),
525534 'required' : True ,
@@ -539,7 +548,7 @@ def __call__(self):
539548 namespace ['__annotations__' ]['jq' ] = str
540549
541550 for name , parameter , click_type , multiple , _converter in optional_parameters :
542- namespace ['__annotations__' ][name ] = click_type
551+ namespace ['__annotations__' ][name ] = _get_class_annotation ( click_type )
543552 option_kwargs = {
544553 'help' : _get_help_from_annotation (parameter .annotation ),
545554 'default' : parameter .default ,
0 commit comments