Skip to content

Commit eb0931c

Browse files
Uniformize message and remove useless details.rst
1 parent 8bd7e5a commit eb0931c

File tree

5 files changed

+21
-26
lines changed

5 files changed

+21
-26
lines changed

doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/details.rst

Lines changed: 0 additions & 3 deletions
This file was deleted.

doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/details.rst

Lines changed: 0 additions & 3 deletions
This file was deleted.

doc/data/messages/u/use-implicit-booleaness-not-comparison/details.rst

Lines changed: 0 additions & 3 deletions
This file was deleted.

doc/whatsnew/fragments/6871.user_action

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ and they now need to be enabled explicitly.
99
The `pylint.extensions.emptystring`` and ``pylint.extensions.compare-to-zero`` extensions
1010
no longer exists and needs to be removed from the ``load-plugins`` option.
1111

12+
Messages related to implicit booleaness were made more explicit and actionable.
13+
1214
This permits to make their likeness explicit and will provide better performance as they share most of their
1315
conditions to be raised.
1416

15-
Refs #6871
17+
Closes #6871

pylint/checkers/refactoring/implicit_booleaness_checker.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,28 @@ class ImplicitBooleanessChecker(checkers.BaseChecker):
6666
"C1802": (
6767
"Do not use `len(SEQUENCE)` without comparison to determine if a sequence is empty",
6868
"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``).",
7472
{"old_names": [("C1801", "len-as-condition")]},
7573
),
7674
"C1803": (
7775
'"%s" can be simplified to "%s", if it is strictly a sequence, as an empty %s is falsey',
7876
"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.",
8282
),
8383
"C1804": (
8484
'"%s" can be simplified to "%s", if it is striclty a string, as an empty string is falsey',
8585
"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.",
8791
{
8892
"default_enabled": False,
8993
"old_names": [("C1901", "compare-to-empty-string")],
@@ -92,7 +96,11 @@ class ImplicitBooleanessChecker(checkers.BaseChecker):
9296
"C1805": (
9397
'"%s" can be simplified to "%s", if it is strictly an int, as 0 is falsey',
9498
"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.",
96104
{"default_enabled": False, "old_names": [("C2001", "compare-to-zero")]},
97105
),
98106
}
@@ -223,12 +231,6 @@ def _check_compare_to_zero(self, node: nodes.Compare) -> None:
223231
)
224232

225233
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-
"""
232234
_operators = {"!=", "==", "is not", "is"}
233235
# note: astroid.Compare has the left most operand in node.left while the rest
234236
# are a list of tuples in node.ops the format of the tuple is

0 commit comments

Comments
 (0)