Files
doc-forge/docforge/models/object.py
Vishesh 'ironeagle' Bangotra 582b6809a0 docs: bring docforge docstrings and wiki to GSDFC standard
- fix GSDFC spec contradictions in __init__ docstring (parenthesized types, fenced-block rule) and sync generated README
- rewrite docstrings across loaders, models, nav, servers, renderers, cli; sync .pyi stubs
- add pydoclint (google style) gate to dev extras and pyproject config
- fix mcp nav resources doc:// -> docs://
- refresh docs/lib and docs/mcp, drop stale docforge/ duplicate group
- update wiki pages and add GSDFC + MCP guides under 05_development
2026-09-12 13:12:51 +05:30

125 lines
3.4 KiB
Python

"""
# Summary
Documentation model representing individual Python objects.
This module defines the `DocObject` class, the fundamental recursive unit of
the doc-forge documentation model. Each `DocObject` represents a Python
entity such as a class, function, method, or attribute, and may contain nested
members that form a hierarchical documentation structure.
---
Notes:
- `DocObject` instances form a tree mirroring the Python import hierarchy.
- Objects are renderer-agnostic and may be consumed by any renderer.
---
"""
from collections.abc import Iterable
class DocObject:
"""
Representation of a documented Python object.
A `DocObject` models a single Python entity discovered during
introspection. Objects may contain nested members, allowing the structure
of modules, classes, and other containers to be represented recursively.
Attributes:
name (str):
Local name of the object.
kind (str):
Type of object (for example `class`, `function`, `method`, or `attribute`).
path (str):
Fully qualified dotted path to the object.
signature (str | None):
Callable signature if the object represents a callable.
docstring (str | None):
Raw docstring text extracted from the source code.
members (dict[str, DocObject]):
Mapping of member names to child `DocObject` instances.
"""
def __init__(
self,
name: str,
kind: str,
path: str,
signature: str | None = None,
docstring: str | None = None,
) -> None:
"""
Initialize a DocObject instance.
Args:
name (str):
Local name of the object.
kind (str):
Object type identifier (for example `class` or `function`).
path (str):
Fully qualified dotted path of the object.
signature (str | None):
Callable signature if applicable.
docstring (str | None):
Documentation string associated with the object.
"""
self.name = name
self.kind = kind
self.path = path
self.signature = signature
self.docstring = docstring
self.members: dict[str, DocObject] = {}
def add_member(self, obj: "DocObject") -> None:
"""
Add a child documentation object.
This is typically used when attaching methods to classes or
nested objects to their parent containers.
Args:
obj (DocObject):
Documentation object to add as a member.
"""
self.members[obj.name] = obj
def get_member(self, name: str) -> "DocObject":
"""
Retrieve a member object by name.
Args:
name (str):
Name of the member to retrieve.
Returns:
DocObject:
The corresponding `DocObject` instance.
Raises:
KeyError:
If the member does not exist.
"""
return self.members[name]
def get_all_members(self) -> Iterable["DocObject"]:
"""
Return all child members of the object.
Returns:
Iterable[DocObject]:
An iterable of `DocObject` instances representing nested members.
"""
return self.members.values()