用额外的metatdata注释类型提示和注释
annotypes的Python项目详细描述
在与mypy和PyCharm兼容的情况下向python类型添加注释
你可以写如下内容:
fromannotypesimportAnno,WithCallTypeswithAnno("The exposure time for the camera"):AExposure=floatwithAnno("The full path to the text file to write"):APath=strclassSimple(WithCallTypes):def__init__(self,exposure,path="/tmp/file.txt"):# type: (AExposure, APath) -> Noneself.exposure=exposureself.path=path
或者Python3号的替代品:
fromannotypesimportAnno,WithCallTypeswithAnno("The exposure time for the camera"):AExposure=floatwithAnno("The full path to the text file to write"):APath=strclassSimple(WithCallTypes):def__init__(self,exposure:AExposure,path:APath="/tmp/file.txt"):self.exposure=exposureself.path=path
在运行时查看应该传递什么来调用它以及它将返回什么:
>>> fromannotypes.py2_examples.simpleimportSimple>>> 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_typeAnno(name='Instance', typ=<class 'annotypes.py2_examples.simple.Simple'>, description='Class instance')
有关更多示例,请参见Python 2 examples或Python 3 examples。
安装
要安装最新版本,请键入:
pip install annotypes
要直接从源代码安装最新代码,请键入:
pip install git+git://github.com/dls-controls/annotypes.git
更改日志
贡献
许可证
阿帕奇许可证。(见LICENSE)