Flo*_*ish 21 python enums warnings pycharm
我有下面的代码,它定义了一个枚举并用于enum.auto()
给出从 1 开始的条目生成值:
from enum import Enum, auto
class Colors(Enum):
RED = auto()
BLUE = auto()
YELLOW = auto()
def main():
print(Colors.RED.value)
print(Colors.BLUE.value)
print(Colors.YELLOW.value)
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
输出:
1
2
3
Run Code Online (Sandbox Code Playgroud)
该代码工作正常并且过去没有任何警告,但今天更新 PyCharm 后,我现在收到以下警告auto()
:
Parameter(s) unfilled
Possible callees:
EnumMeta.__call__(cls: Type[_T], value, names: None = ...)
EnumMeta.__call__(cls: EnumMeta, value: str, names: Union[str, Iterable[str], Iterable[Iterable[str]], Mapping[str, Any]], *, module: Optional[str] = ..., qualname: Optional[str] = ..., type: Optional[type] = ..., start: int = ..., boundary: Optional[FlagBoundary] = ...)
EnumMeta.__call__(cls: Type[_T], value, names: None = ...)
EnumMeta.__call__(cls: EnumMeta, value: str, names: Union[str, Iterable[str], Iterable[Iterable[str]], Mapping[str, Any]], *, module: Optional[str] = ..., qualname: Optional[str] = ..., type: Optional[type] = ..., start: int = ...)
Run Code Online (Sandbox Code Playgroud)
我检查了Python 文档,但找不到任何相关内容,因为所有示例仍然auto()
不带任何参数。
我认为新警告是因为 PyCharm 使用更新的 Python linting 规则。
我该如何解决这个警告?
更新1:
看来 PyCharm 正在检测enum.auto()
as enum.auto(IntFlag)
,因此警告参数未填充:
我还将向 PyCharm 开发人员报告此问题。也许这是一个错误。
更新2:
没关系,大家。我刚刚发现这是一个错误,并在一个月前在这里报告。
更新3:
bug终于被修复了!
这是一个 IDE 错误(正如 OP 已经提到的),您应该像这样抑制警告:
# noinspection PyArgumentList
class Colors(Enum):
RED = auto()
BLUE = auto()
YELLOW = auto()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2419 次 |
最近记录: |