generate_class_stub¶
- generate_class_stub(cls: type, ctx: StubContext) str[source]¶
Generate the full
.pyiblock for cls.Dispatches to specialised generators for NamedTuple subclasses and dataclasses before falling back to standard reflection. Abstract methods receive
@abstractmethod; async methods receiveasync def.- Parameters:
cls (type) – The class to stub.
ctx (StubContext) – The current
StubContext.
- 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.