Skip to content

Commit dd87065

Browse files
committed
Fix issues with package removal
1 parent bb87417 commit dd87065

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/lazydocs/generation.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ def _get_function_signature(
144144
return_type = inspect.signature(function).return_annotation.__name__
145145
except Exception:
146146
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)
148152

149153
for parameter in parameters:
150154
argument = str(parameters[parameter])
@@ -153,6 +157,17 @@ def _get_function_signature(
153157
continue
154158
# Reintroduce Optionals
155159
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)
156171
arguments.append(argument)
157172
else:
158173
print("Seems like function " + name + " does not have any signature")
@@ -168,9 +183,6 @@ def _get_function_signature(
168183

169184
signature += ")" + ((" → " + return_type) if return_type else "")
170185

171-
if remove_package:
172-
# Remove all package path from signature
173-
signature = re.sub(r"([a-zA-Z0-9_]*?\.)", "", signature)
174186
return signature
175187

176188

0 commit comments

Comments
 (0)