Coming from docrep¶
docrep solves the same problem by
templating: you register a docstring’s sections under a key and interpolate
them into another docstring with %(key.parameters)s. docshare does it by
composition instead — you name the object to inherit from, and it works out
which items apply.
# docrep
from docrep import DocstringProcessor
docstrings = DocstringProcessor()
@docstrings.get_sectionsf('base')
@docstrings.dedent
def base(x, y):
"""..."""
@docstrings.dedent
def derived(x, y, z):
"""Summary.
Parameters
----------
%(base.parameters)s
z : int
The z.
"""
# docshare
from docshare import docwrap
def base(x, y):
"""..."""
@docwrap(format='numpy', inheritparams=base)
def derived(x, y, z):
"""Summary.
Parameters
----------
z : int
The z.
"""
Rough equivalents¶
|
|
|---|---|
|
nothing; no shared state |
|
nothing; any documented object is a source |
|
|
|
nothing; docstrings are always dedented |
|
|
|
usually nothing — see below |
|
|
|
nothing; summaries are never inherited |
Differences worth knowing¶
- No interpolation.
Nothing is substituted into your docstring, so a literal
%needs no escaping and a missing key cannot silently vanish.- No registration.
A source is any object with a docstring. It does not need decorating, and it does not need to be yours — a function from NumPy or from any other library works.
keep_paramsis usually unnecessary.docshareinherits only the parameters the decorated object actually has, so a source with extra parameters needs no filtering.- Placement is automatic.
Inherited parameters are ordered by your signature rather than by where you put the substitution.
- Google style is supported.
docrepis NumPy only.- Summaries and descriptions are never inherited.
docrepcan copy them explicitly;docsharetreats them as yours.- Your signature is checked.
Documentation naming a parameter you do not have is reported rather than passed through. See Signatures.