[CodeStyle][E712] use if cond
/if cond is True
for comparison with True
#47464
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Others
PR changes
Others
Describe
解决 Flake8 E712 问题(comparison to True should be ‘if cond is True:’ or ‘if cond:’)
x == True
->x
/x is True
x != True
->not x
/x is not True
x == False
->not x
/x is False
x != False
->not x
/x is not False
以
x == False
为例子,分情况考虑如何修改False
相等,只是用于逻辑比较 -> 直接not x
(大多数情况)False
,而[]
、None
、""
等 falsy value 则需要用is
->x is False
__eq__
,则需要额外考虑修改方案,比如x
为 bool 类型的 np.ndarray,修改为~x
即可具体所使用工具及命令如下:
Related links