Annotating type hints and comments with extra metatdata
Project description
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)
Project details
Release history Release notifications | RSS feed
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.15.tar.gz
(22.9 kB
view details)
File details
Details for the file annotypes-0.15.tar.gz
.
File metadata
- Download URL: annotypes-0.15.tar.gz
- Upload date:
- Size: 22.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7aca8507ccb29a5875aab6d9fe403c5f7de1d0442c81f3c2d9000df9b9b6bbc1 |
|
MD5 | de4e251e6e8faf493412b7271da18e5b |
|
BLAKE2b-256 | 40dab799e2845ca94d25cc41eb3c3ae80079cca15ab3cf437a501df2891a06c7 |