跳到内容

unnecessary-literal-set (C405)

Derived from the flake8-comprehensions linter. (源自 flake8-comprehensions linter。)

修复总是可用的。

作用

检查 set() 调用,这些调用接受不必要的列表或元组字面量作为参数。

为什么这不好?

set() 调用中使用列表或元组字面量是不必要的。相反,表达式可以重写为集合字面量。

示例

set([1, 2])
set((1, 2))
set([])

建议改为

{1, 2}
{1, 2}
set()

修复安全性

This rule's fix is marked as unsafe, as it may occasionally drop comments when rewriting the call. In most cases, though, comments will be preserved. (此规则的修复被标记为不安全,因为它在重写调用时有时会删除注释。但在大多数情况下,注释将被保留。)