Skip to main content

Annotating type hints and comments with extra metatdata

Project description

Build Status Test coverage Latest PyPI version

Adding annotations to Python types while still being compatible with mypy and PyCharm

You can write things like:

from annotypes import Anno, WithCallTypes

with Anno("The exposure to be active for"):
    Exposure = float
with Anno("The full path to the text file to write"):
    Path = str

class Simple(WithCallTypes):
    def __init__(self, exposure, path="/tmp/file.txt"):
        # type: (Exposure, Path) -> None
        self.exposure = exposure
        self.path = path

or the Python3 alternative:

from annotypes import Anno, WithCallTypes

with Anno("The exposure to be active for"):
    Exposure = float
with Anno("The full path to the text file to write"):
    Path = str

class Simple(WithCallTypes):
    def __init__(self, exposure: Exposure, path: Path = "/tmp/file.txt"):
        self.exposure = exposure
        self.path = path

And at runtime see what you should pass to call it and what it will return:

>>> from annotypes.py2_examples.simple import Simple
>>> list(Simple.call_types)
['exposure', 'path']
>>> Simple.call_types['exposure']
Anno(name='Exposure', typ=<type 'float'>, description='The exposure to be active for')
>>> Simple.return_type
Anno(name='Instance', typ=<class 'annotypes.py2_examples.simple.Simple'>, description='Class instance')

For more examples see the Python 2 examples or Python 3 examples.

Installation

To install the latest release, type:

pip install annotypes

To install the latest code directly from source, type:

pip install git+git://github.com/dls-controls/annotypes.git

Changelog

See CHANGELOG

Contributing

See CONTRIBUTING

License

APACHE License. (see LICENSE)

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

annotypes-0.9.1.tar.gz (18.3 kB view details)

Uploaded Source

File details

Details for the file annotypes-0.9.1.tar.gz.

File metadata

  • Download URL: annotypes-0.9.1.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for annotypes-0.9.1.tar.gz
Algorithm Hash digest
SHA256 89655d2f187c0ec4a276eca451f9811fc9dee51430e35f72ceca4666e43dcd48
MD5 0437f02cce097e40eecc546ee9ed1b6f
BLAKE2b-256 6c3ff1a22b6094888a3bc4c13a0143ed4bb15acb6a42904704564d83a8d46c75

See more details on using hashes here.

Supported by

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