The stubdoc library now supports a top-level class docstring.
Related issue
5
Examples
Original module code:
py
from random import randint
sample_int: int = 100
def sample_func(a: int, b: str) -> bool:
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
ed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Parameters
----------
a : int
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
b : str
ed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Returns
-------
c : bool
Ut enim ad minim veniam, quis nostrud exercitation.
"""
return True
class SampleClass:
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam.
"""
def __init__(self) -> None:
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
"""
property
def sample_property(self) -> int:
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Returns
-------
d : int
ed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
"""
return randint(0, 100)
Original stub file (create with the mypy command):
py
sample_int: int
def sample_func(a: int, b: str) -> bool: ...
class SampleClass:
def __init__(self) -> None: ...
property
def sample_property(self) -> int: ...
After the stubdoc command (`$ stubdoc -m samples/sample.py -s out/samples/sample.pyi`) stubfile becomes as follows:
py
sample_int: int
def sample_func(a: int, b: str) -> bool:
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
ed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Parameters
----------
a : int
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
b : str
ed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Returns
-------
c : bool
Ut enim ad minim veniam, quis nostrud exercitation.
"""
class SampleClass:
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam.
"""
def __init__(self) -> None:
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
"""
property
def sample_property(self) -> int:
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Returns
-------
d : int
ed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
"""