generate_class_stub

generate_class_stub(cls: type, ctx: StubContext) str[source]

Generate the full .pyi block for cls.

Dispatches to specialised generators for NamedTuple subclasses and dataclasses before falling back to standard reflection. Abstract methods receive @abstractmethod; async methods receive async def.

Parameters:
Returns:

str – Complete class stub as a multi-line string without a trailing newline.

Examples

>>> from stubpy.context import StubContext
>>> class Point:
...     x: float
...     y: float
...     def __init__(self, x: float, y: float) -> None: ...
>>> stub = generate_class_stub(Point, StubContext())
>>> "class Point:" in stub
True
>>> "x: float" in stub
True

See also

Public API reference — overview of all public names.