Skip to main content

Python stub file generator.

Project description

pygenstub is a utility for generating stub files from Python 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.python.org/pypi/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: ...

Usage

pygenstub can be installed 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.

pygenstub consists of a single module which itself contains signature fields and commands as described in the documentation. You can see the source code and the autogenerated stub file as an example.

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.

Source Distribution

pygenstub-1.0b4.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygenstub-1.0b4-py2.py3-none-any.whl (11.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pygenstub-1.0b4.tar.gz.

File metadata

  • Download URL: pygenstub-1.0b4.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pygenstub-1.0b4.tar.gz
Algorithm Hash digest
SHA256 618b05e377c8cd45256033a3332292d9d94163b655cc511e52994c42693adb34
MD5 7320be5d946df9907d20758a86942fec
BLAKE2b-256 2e242374455708cdb1d15b022140529a22f18b01e42e9888e2fb9d93afb16e78

See more details on using hashes here.

File details

Details for the file pygenstub-1.0b4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pygenstub-1.0b4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c7e57a53cf1eadf11d337cd04c579c5d51ac6588580d9b66e581c4557ea5f1cf
MD5 489af692169445ccc83a69cf36b0f413
BLAKE2b-256 d07aa8b15544363dd9f2f3f0db4cb75a6874bf81786a9aff8f52016cc259f326

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page