【发布时间】:2020-04-25 12:14:42
【问题描述】:
我在 python 中有这一行;
set1 = set() # create empty set
当我使用 mypi 扫描时,我收到错误 Need type annotation for 'set1'
如何给空集类型注解?
我在 pycharm 中使用 python 3.7 和 mypi 插件。
【问题讨论】:
标签: python python-3.x static-typing python-typing
我在 python 中有这一行;
set1 = set() # create empty set
当我使用 mypi 扫描时,我收到错误 Need type annotation for 'set1'
如何给空集类型注解?
我在 pycharm 中使用 python 3.7 和 mypi 插件。
【问题讨论】:
标签: python python-3.x static-typing python-typing
简单版:set1: set = set()
更具体的版本:
from typing import Set
set1: Set[<type>] = set()
例如对于字符串集:set1: Set[str] = set()
【讨论】:
我不确定什么是需要类型注释,但该注释只是
set1<b>: set</b> = set()
【讨论】: