跳转到主要内容

为类型提示和注释添加额外元数据

项目描述

Build Status Test coverage Latest PyPI version

添加注释到Python类型,同时保持与 mypyPyCharm 兼容

您可以编写如下内容

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

变更日志

CHANGELOG

贡献

CONTRIBUTING

许可证

APACHE许可证。(见 LICENSE

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

annotypes-0.21.tar.gz (19.4 kB 查看哈希值)

上传时间:

由以下提供支持