compare-to-empty-string / C1901#
Message emitted:
"%s" can be simplified to "%s" as an empty string is falsey
Description:
Used when Pylint detects comparison to an empty string constant.
Problematic code:
x = ""
y = "hello"
if x == "": # [compare-to-empty-string]
print("x is an empty string")
if y != "": # [compare-to-empty-string]
print("y is not an empty string")
Correct code:
x = ""
y = "hello"
if not x:
print("x is an empty string")
if y:
print("y is not an empty string")
Configuration file:
[main]
load-plugins=pylint.extensions.emptystring
Note
- This message is emitted by the optional 'compare-to-empty-string'
checker which requires the
pylint.extensions.emptystring
plugin to be loaded.
Created by the compare-to-empty-string checker.