An extension to Sphinx `autodoc` to augment sphinx documentation with type annotations, when using Python 2 style type annotations.
Project description
An extension to Sphinx autodoc to augment sphinx documentation with type annotations, when using Python 2 style type annotations.
The Problem
Python 2 doesn’t support type annotations. Thus writing Python 2 / Python 3 agnostic code with type annotations requires putting the type annotations in comments:
def add(x, y):
# type: (int, int) -> int
"""Adds two numbers."""
return x + y
But now when documentation is generated with sphinx, the documentation doesn’t include type annotations:
Example from the Signatory project.
The Solution
This extension remedies things so that the Sphinx documentation now looks like:
(which is the same as what you’d get using Python 3 style type annotations e.g. def add(x: int, y: int) -> int
)
Installation
Via pip:
pip install py2annotate
It’s also just a single file, so copy-paste the code if you want.
Usage
Just add py2annotate to the list of extensions in conf.py:
# conf.py
...
extensions = ['sphinx.ext.autodoc', 'py2annotate']
...
(It shouldn’t actually matter whether it comes before or after autodoc.)
Note that Sphinx itself must be run using Python 3, not Python 2. This is because py2annotate uses the Python 3 style type annotations internally in order to determine the correct annotations.
Known Issues
None so far! File a report if you run into anything.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py2annotate-1.0.0.tar.gz
.
File metadata
- Download URL: py2annotate-1.0.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.5.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06afad4d4d62bbb8746bbbf8432398fcd1c18baa77b72c81a23eeaf4699c5213 |
|
MD5 | e1af5e9db7ce18c2040b40ea3a318fdc |
|
BLAKE2b-256 | 57a3c0b798c3972b82b5ea4cad1c089cfb033de622cf18a4e30d099737004ddb |
File details
Details for the file py2annotate-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: py2annotate-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.5.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e91d378049af36d69c80603c7c3d2076f37f7992519567acfc411b9aae30a290 |
|
MD5 | 9177f1ff5fdaa2fce185f426d917b4c0 |
|
BLAKE2b-256 | cfa14fde9274204fee316485c6531d2eb0d453701a81435cc51d81157cb11602 |