@@ -144,7 +144,11 @@ def _get_function_signature(
144
144
return_type = inspect .signature (function ).return_annotation .__name__
145
145
except Exception :
146
146
pass
147
- return_type = return_type .lstrip ("typing." )
147
+ # Remove all typing path prefixes
148
+ return_type = return_type .replace ("typing." , "" )
149
+ if remove_package :
150
+ # Remove all package path return type
151
+ return_type = re .sub (r"([a-zA-Z0-9_]*?\.)" , "" , return_type )
148
152
149
153
for parameter in parameters :
150
154
argument = str (parameters [parameter ])
@@ -153,6 +157,17 @@ def _get_function_signature(
153
157
continue
154
158
# Reintroduce Optionals
155
159
argument = re .sub (r"Union\[(.*?), NoneType\]" , r"Optional[\1]" , argument )
160
+
161
+ # Remove package
162
+ if remove_package :
163
+ # Remove all package path from parameter signature
164
+ if "=" not in argument :
165
+ argument = re .sub (r"([a-zA-Z0-9_]*?\.)" , "" , argument )
166
+ else :
167
+ # Remove only from part before the first =
168
+ argument_split = argument .split ("=" )
169
+ argument_split [0 ] = re .sub (r"([a-zA-Z0-9_]*?\.)" , "" , argument_split [0 ])
170
+ argument = "=" .join (argument_split )
156
171
arguments .append (argument )
157
172
else :
158
173
print ("Seems like function " + name + " does not have any signature" )
@@ -168,9 +183,6 @@ def _get_function_signature(
168
183
169
184
signature += ")" + ((" → " + return_type ) if return_type else "" )
170
185
171
- if remove_package :
172
- # Remove all package path from signature
173
- signature = re .sub (r"([a-zA-Z0-9_]*?\.)" , "" , signature )
174
186
return signature
175
187
176
188
0 commit comments