Skip to content

danields761/class-doc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Class doc

Small set of helpers aimed to extract class attributes documentation from the class definition. This stuff tries to mimic sphinx-autodoc behaviour as closely as possible (except instance attributes defined inside __init__ function).

The main advantage of this project over sphinx-autodoc is that it is lightweight single-purpose dependency, while autodoc just a small part of really heavy project.

Installation

This package is available on PyPI

pip install class-doc

Examples

Shamely stolen from sphinx-autodoc docs

class Foo:
    """Docstring for class Foo."""

    #: Doc comment for class attribute Foo.bar.
    #: It can have multiple lines.
    bar = 1

    flox = 1.5   #: Doc comment for Foo.flox. One line only.

    baz = 2
    """Docstring for class attribute Foo.baz."""
    
    baf = 3
    """
    Even
    multiline
    docstrings
    handled
    properly
    """



import class_doc
assert class_doc.extract_docs_from_cls_obj(Foo) == {
    "bar": ["Doc comment for class attribute Foo.bar.", "It can have multiple lines."],
    "flox": ["Doc comment for Foo.flox. One line only."],
    "baz": ["Docstring for class attribute Foo.baz."],
    "baf": ["Even", "multiline", "docstrings", "handled", "properly"]
}

Development setup

Project requires Poetry for development setup.

  • If you aren't have it already
pip install poetry
  • Install project dependencies
poetry install
  • Run tests
poetry run pytest .
  • Great, all works!

About

Extract attributes docstrings defined in various ways

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages