assignment-default-in-stub (PYI015) (存根中的赋值默认值 (PYI015))
源自 flake8-pyi 代码检查器。
修复总是可用的。
作用
Checks for assignments in stubs with default values that are not "simple" (i.e., int
, float
, complex
, bytes
, str
, bool
, None
, ...
, or simple container literals). (检查存根中具有非“简单”默认值的赋值(即,int
、float
、complex
、bytes
、str
、bool
、None
、...
或简单容器字面量)。)
为什么这不好?
Stub (.pyi
) files exist to define type hints, and are not evaluated at runtime. As such, assignments in stub files should not include values, as they are ignored by type checkers. (存根 (.pyi
) 文件用于定义类型提示,并且不会在运行时进行评估。因此,存根文件中的赋值不应包含值,因为类型检查器会忽略它们。)
However, the use of such values may be useful for IDEs and other consumers of stub files, and so "simple" values may be worth including and are permitted by this rule. (但是,使用此类值可能对 IDE 和存根文件的其他使用者有用,因此“简单”值可能值得包含,并且此规则允许使用。)
Instead of including and reproducing a complex value, use ...
to indicate that the assignment has a default value, but that the value is non-simple or varies according to the current platform or Python version. (与其包含和重现复杂值,不如使用 ...
来指示赋值具有默认值,但该值不是简单的值,或者因当前平台或 Python 版本而异。)
示例
建议改为