Files
doc-forge/docforge/models/module.py
Vishesh 'ironeagle' Bangotra 4a876abc62 refactor: rename loader/model packages to loaders/models
- Rename docforge.loader → docforge.loaders and docforge.model → docforge.models
- Update all imports, type stubs, CLI, tests, and documentation references
- Align MkDocs navigation and docforge.nav.yml with new package structure
- Adjust module docstrings and comments for consistency with pluralized naming
2026-01-21 15:45:48 +05:30

67 lines
1.6 KiB
Python

"""
This module defines the Module class, which represents a Python module or package
in the doc-forge documentation models. It acts as a container for top-level
documented objects.
"""
from typing import Dict, Iterable, Optional
from docforge.models.object import DocObject
class Module:
"""
Represents a documented Python module or package.
Attributes:
path: Dotted import path of the module.
docstring: Module-level docstring content.
members: Dictionary mapping object names to their DocObject representations.
"""
def __init__(
self,
path: str,
docstring: Optional[str] = None,
) -> None:
"""
Initialize a new Module.
Args:
path: The dotted path of the module.
docstring: The module's docstring, if any.
"""
self.path = path
self.docstring = docstring
self.members: Dict[str, DocObject] = {}
def add_object(self, obj: DocObject) -> None:
"""
Add a documented object to the module.
Args:
obj: The object to add.
"""
self.members[obj.name] = obj
def get_object(self, name: str) -> DocObject:
"""
Retrieve a member object by name.
Args:
name: The name of the object.
Returns:
The requested DocObject.
"""
return self.members[name]
def get_all_objects(self) -> Iterable[DocObject]:
"""
Get all top-level objects in the module.
Returns:
An iterable of DocObject instances.
"""
return self.members.values()