Skip to content

Instantly share code, notes, and snippets.

@a-recknagel
Created October 29, 2020 12:32
Show Gist options
  • Save a-recknagel/e2de5b9ca21383e9f0606eb08a6ee50e to your computer and use it in GitHub Desktop.
Save a-recknagel/e2de5b9ca21383e9f0606eb08a6ee50e to your computer and use it in GitHub Desktop.
MCVE to reproduce sphinx's classvar appending
import sys
sys.path.append('src')
project = "sphinx_test"
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.napoleon",
]

Doc Index

.. toctree::
   :maxdepth: 3
   :glob:

   autodoc/*
import dataclasses
@dataclasses.dataclass
class Foo:
"""Docstring for Foo"""
var_a: str
var_b: int
@a-recknagel
Copy link
Author

a-recknagel commented Oct 29, 2020

store files as:

.
├── docs
│   ├── conf.py
│   └── index.rst
└── src
    └── dc.py

Then build documentation and open documentation by running

$ python3.7 -m venv venv  # or 3.8, or 3.9
$ source venv/bin/activate
(venv) $ pip install sphinx
(venv) $ sphinx-apidoc --no-toc -o docs/autodoc src/
(venv) $ sphinx-build -b html docs/ public
(venv) $ xdg-open public/autodoc/dc.html

The offending items are the var_a and var_b parts at the bottom of the class description that weren't part of the class docstring:

Screenshot from 2020-10-29 13-56-59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment