Skip to content

dls-controls/annotypes

Repository files navigation

AnnoTypes

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 time for the camera"):
    AExposure = float
with Anno("The full path to the text file to write"):
    APath = str

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

or the Python3 alternative:

from annotypes import Anno, WithCallTypes

with Anno("The exposure time for the camera"):
    AExposure = float
with Anno("The full path to the text file to write"):
    APath = str

class Simple(WithCallTypes):
    def __init__(self, exposure: AExposure, path: APath = "/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='AExposure', typ=<type 'float'>, description='The exposure time for the camera')
>>> 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)

About

Annotating Python type hints and comments with extra metatdata

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •