@@ -66,24 +66,28 @@ class ImplicitBooleanessChecker(checkers.BaseChecker):
66
66
"C1802" : (
67
67
"Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty" ,
68
68
"use-implicit-booleaness-not-len" ,
69
- "Used when Pylint detects that len(sequence) is being used "
70
- "without explicit comparison inside a condition to determine if a sequence is empty. "
71
- "Instead of coercing the length to a boolean, either "
72
- "rely on the fact that empty sequences are false or "
73
- "compare the length against a scalar." ,
69
+ "Empty sequences are considered false in a boolean context. You can either"
70
+ " remove the call to 'len' (``if not x``) or compare the length against a"
71
+ "scalar (``if len(x) > 1``)." ,
74
72
{"old_names" : [("C1801" , "len-as-condition" )]},
75
73
),
76
74
"C1803" : (
77
75
'"%s" can be simplified to "%s", if it is strictly a sequence, as an empty %s is falsey' ,
78
76
"use-implicit-booleaness-not-comparison" ,
79
- "Used when Pylint detects that collection literal comparison is being "
80
- "used to check for emptiness; Use implicit booleaness instead "
81
- "of a collection classes; empty collections are considered as false" ,
77
+ "Empty sequences are considered false in a boolean context. Following this"
78
+ " check blindly in weakly typed code base can create hard to debug issues."
79
+ " If the value can be something else that is falsey but not a sequence (for"
80
+ " example ``None``, an empty string, or ``0``) the code will not be "
81
+ "equivalent." ,
82
82
),
83
83
"C1804" : (
84
84
'"%s" can be simplified to "%s", if it is striclty a string, as an empty string is falsey' ,
85
85
"use-implicit-booleaness-not-comparison-to-string" ,
86
- "Used when Pylint detects comparison to an empty string constant." ,
86
+ "Empty string are considered false in a boolean context. Following this"
87
+ " check blindly in weakly typed code base can create hard to debug issues."
88
+ " If the value can be something else that is falsey but not a string (for"
89
+ " example ``None``, an empty sequence, or ``0``) the code will not be "
90
+ "equivalent." ,
87
91
{
88
92
"default_enabled" : False ,
89
93
"old_names" : [("C1901" , "compare-to-empty-string" )],
@@ -92,7 +96,11 @@ class ImplicitBooleanessChecker(checkers.BaseChecker):
92
96
"C1805" : (
93
97
'"%s" can be simplified to "%s", if it is strictly an int, as 0 is falsey' ,
94
98
"use-implicit-booleaness-not-comparison-to-zero" ,
95
- "Used when Pylint detects comparison to a 0 constant." ,
99
+ "0 is considered false in a boolean context. Following this"
100
+ " check blindly in weakly typed code base can create hard to debug issues."
101
+ " If the value can be something else that is falsey but not an int (for"
102
+ " example ``None``, an empty string, or an empty sequence) the code will not be "
103
+ "equivalent." ,
96
104
{"default_enabled" : False , "old_names" : [("C2001" , "compare-to-zero" )]},
97
105
),
98
106
}
@@ -223,12 +231,6 @@ def _check_compare_to_zero(self, node: nodes.Compare) -> None:
223
231
)
224
232
225
233
def _check_compare_to_string (self , node : nodes .Compare ) -> None :
226
- """Checks for comparisons to empty string.
227
-
228
- Most of the time you should use the fact that empty strings are false.
229
- An exception to this rule is when an empty string value is allowed in the program
230
- and has a different meaning than None!
231
- """
232
234
_operators = {"!=" , "==" , "is not" , "is" }
233
235
# note: astroid.Compare has the left most operand in node.left while the rest
234
236
# are a list of tuples in node.ops the format of the tuple is
0 commit comments