Skip to content

Commit

Permalink
Catch exceptions in mkdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
breuleux committed Dec 12, 2024
1 parent 7941bc4 commit 2877e35
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/ovld/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,26 @@ def analyze_arguments(self):
return self.argument_analysis

def mkdoc(self):
docs = [fn.__doc__ for fn in self.defns.values() if fn.__doc__]
if len(docs) == 1:
maindoc = docs[0]
else:
maindoc = f"Ovld with {len(self.defns)} methods."

doc = f"{maindoc}\n\n"
for fn in self.defns.values():
fndef = inspect.signature(fn)
fdoc = fn.__doc__
if not fdoc or fdoc == maindoc:
doc += f"{self.__name__}{fndef}\n\n"
try:
docs = [fn.__doc__ for fn in self.defns.values() if fn.__doc__]
if len(docs) == 1:
maindoc = docs[0]
else:
if not fdoc.strip(" ").endswith("\n"):
fdoc += "\n"
fdoc = textwrap.indent(fdoc, " " * 4)
doc += f"{self.__name__}{fndef}\n{fdoc}\n"
maindoc = f"Ovld with {len(self.defns)} methods."

doc = f"{maindoc}\n\n"
for fn in self.defns.values():
fndef = inspect.signature(fn)
fdoc = fn.__doc__
if not fdoc or fdoc == maindoc:
doc += f"{self.__name__}{fndef}\n\n"
else:
if not fdoc.strip(" ").endswith("\n"):
fdoc += "\n"
fdoc = textwrap.indent(fdoc, " " * 4)
doc += f"{self.__name__}{fndef}\n{fdoc}\n"
except Exception as exc: # pragma: no cover
doc = f"An exception occurred when calculating the docstring: {exc}"
return doc

@property
Expand Down

0 comments on commit 2877e35

Please sign in to comment.