Skip to main content

Python stub file generator.

Project description

Copyright (C) 2016-2018 H. Turgut Uyar <uyar@tekir.org>

pygenstub is a utility for generating stub files from docstrings in source files. It takes a source file as input and creates a stub file with the same base name and the .pyi extension.

PyPI:https://pypi.org/project/pygenstub/
Repository:https://bitbucket.org/uyar/pygenstub
Documentation:https://pygenstub.readthedocs.io/

If the docstring of a function includes a sig field, the value of that field will be used to generate a prototype by matching the types to the parameters in the same order. For example, for the code given below:

def foo(a, b):
    """Do foo.

    :sig: (int, str) -> None
    """

pygenstub will generate the following stub:

def foo(a: int, b: str) -> None: ...

pygenstub consists of a single module which itself contains signatures. You can see the source code and the autogenerated stub file as an example.

Usage

pygenstub has been tested with Python 2.7, Python 3.4+, PyPy2 5.7+, and PyPy3 5.7+. You can install the latest version using pip:

pip install pygenstub

Installation creates a script named pygenstub which can be used as follows:

pygenstub foo.py

This command will generate the file foo.pyi in the same directory as the input file. If the output file already exists, it will be overwritten.

Sphinx autodoc support

If pygenstub is activated as a Sphinx extension (after autodoc), it will insert type comments for parameters and return values in the docstring. It will also remove the signature fields to exclude them from the output:

extensions = [
    'sphinx.ext.autodoc',
    'pygenstub'
]

As an example of the output, you can see the API documentation for pygenstub itself.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
pygenstub-1.1-py2.py3-none-any.whl (10.1 kB) Copy SHA256 hash SHA256 Wheel py2.py3 May 25, 2018
pygenstub-1.1.tar.gz (29.8 kB) Copy SHA256 hash SHA256 Source None May 25, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page