Skip to content

Commit 8931df8

Browse files
authored
fix: Add source to class objects
PR #120: #120
1 parent 4b99cbc commit 8931df8

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/pytkdocs/loader.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,21 @@ def get_class_documentation(self, node: ObjectNode, select_members=None) -> Clas
460460
class_ = node.obj
461461
docstring = inspect.cleandoc(class_.__doc__ or "")
462462
bases = [self._class_path(b) for b in class_.__bases__]
463+
464+
source: Optional[Source]
465+
466+
try:
467+
source = Source(*inspect.getsourcelines(node.obj))
468+
except (OSError, TypeError) as error:
469+
source = None
470+
463471
root_object = Class(
464-
name=node.name, path=node.dotted_path, file_path=node.file_path, docstring=docstring, bases=bases
472+
name=node.name,
473+
path=node.dotted_path,
474+
file_path=node.file_path,
475+
docstring=docstring,
476+
bases=bases,
477+
source=source,
465478
)
466479

467480
# Even if we don't select members, we want to correctly parse the docstring

0 commit comments

Comments
 (0)