为类型提示和注释添加额外元数据
项目描述
添加注释到Python类型,同时保持与 mypy 和 PyCharm 兼容
您可以编写如下内容
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
或者Python 3的替代方案
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
在运行时看到调用它时应传递什么以及它将返回什么
>>> 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')
更多示例请参阅 Python 2示例 或 Python 3示例。
安装
要安装最新版本,请输入
pip install annotypes
要直接从源代码安装最新代码,请输入
pip install git+git://github.com/dls-controls/annotypes.git
变更日志
贡献
许可证
APACHE许可证。(见 LICENSE)
项目详情
关闭
annotypes-0.21.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b330a35b7ae25ab97741dc40c0fb9c6ce64204a7f100e83d70655e5815dda650 |
|
MD5 | 497b6853fcc2e218f719dcc824c6e351 |
|
BLAKE2b-256 | 16c51113740fa4c1279d34b756002ca0ec8e138f4a360a8fcf78abff88cc19e5 |