@@ -67,45 +67,23 @@ def extract_args_from_signature(operation, excluded_params=None):
67
67
""" Extracts basic argument data from an operation's signature and docstring
68
68
excluded_params: List of params to ignore and not extract. By default we ignore ['self', 'kwargs'].
69
69
"""
70
- args = []
71
- try :
72
- # only supported in python3 - falling back to argspec if not available
73
- sig = inspect .signature (operation )
74
- args = sig .parameters
75
- except AttributeError :
76
- sig = inspect .getargspec (operation ) # pylint: disable=deprecated-method, useless-suppression
77
- args = sig .args
70
+ sig = inspect .signature (operation )
71
+ args = sig .parameters
78
72
79
73
arg_docstring_help = option_descriptions (operation )
80
74
excluded_params = excluded_params or ['self' , 'kwargs' ]
81
75
82
76
for arg_name in [a for a in args if a not in excluded_params ]:
83
- try :
84
- # this works in python3
85
- default = args [arg_name ].default
86
- required = default == inspect .Parameter .empty # pylint: disable=no-member, useless-suppression
87
- except TypeError :
88
- arg_defaults = (dict (zip (sig .args [- len (sig .defaults ):], sig .defaults ))
89
- if sig .defaults
90
- else {})
91
- default = arg_defaults .get (arg_name )
92
- required = arg_name not in arg_defaults
93
-
77
+ default = args [arg_name ].default
78
+ required = default == inspect .Parameter .empty
94
79
action = 'store_' + str (not default ).lower () if isinstance (default , bool ) else None
95
-
96
- try :
97
- default = (default
98
- if default != inspect ._empty # pylint: disable=protected-access
99
- else None )
100
- except AttributeError :
101
- pass
102
-
80
+ command_argument_default = default if default != inspect .Parameter .empty else None
103
81
options_list = ['--' + arg_name .replace ('_' , '-' )]
104
82
help_str = arg_docstring_help .get (arg_name )
105
83
106
84
yield (arg_name , CLICommandArgument (arg_name ,
107
85
options_list = options_list ,
108
86
required = required ,
109
- default = default ,
87
+ default = command_argument_default ,
110
88
help = help_str ,
111
89
action = action ))
0 commit comments