summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2023-04-26 13:16:21 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2023-05-02 20:01:39 +0200
commit26686d544eab7236a92e56cc90c34b6e3a37f473 (patch)
treeca93e25911bdaa0608653d2a215d0b0fda5fbe1a /doc
parent87fe5e58c2013b4b1949836c142993464b153237 (diff)
downloadpylint-git-26686d544eab7236a92e56cc90c34b6e3a37f473.tar.gz
Merge the compare-to-zero extensions to 'implicit_booleaness_checker'
Diffstat (limited to 'doc')
-rw-r--r--doc/data/messages/c/compare-to-zero/bad.py8
-rw-r--r--doc/data/messages/c/compare-to-zero/good.py8
-rw-r--r--doc/data/messages/c/compare-to-zero/pylintrc2
-rw-r--r--doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/bad.py6
-rw-r--r--doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/details.rst3
-rw-r--r--doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/good.py6
-rw-r--r--doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/pylintrc2
-rw-r--r--doc/user_guide/checkers/extensions.rst15
-rw-r--r--doc/user_guide/checkers/features.rst2
-rw-r--r--doc/user_guide/configuration/all-options.rst2
-rw-r--r--doc/user_guide/messages/messages_overview.rst3
-rw-r--r--doc/whatsnew/fragments/6871.user_action12
12 files changed, 34 insertions, 35 deletions
diff --git a/doc/data/messages/c/compare-to-zero/bad.py b/doc/data/messages/c/compare-to-zero/bad.py
deleted file mode 100644
index c987403a4..000000000
--- a/doc/data/messages/c/compare-to-zero/bad.py
+++ /dev/null
@@ -1,8 +0,0 @@
-x = 0
-y = 1
-
-if x == 0: # [compare-to-zero]
- print("x is equal to zero")
-
-if y != 0: # [compare-to-zero]
- print("y is not equal to zero")
diff --git a/doc/data/messages/c/compare-to-zero/good.py b/doc/data/messages/c/compare-to-zero/good.py
deleted file mode 100644
index bea3733e2..000000000
--- a/doc/data/messages/c/compare-to-zero/good.py
+++ /dev/null
@@ -1,8 +0,0 @@
-x = 0
-y = 1
-
-if not x:
- print("x is equal to zero")
-
-if y:
- print("y is not equal to zero")
diff --git a/doc/data/messages/c/compare-to-zero/pylintrc b/doc/data/messages/c/compare-to-zero/pylintrc
deleted file mode 100644
index 895291f84..000000000
--- a/doc/data/messages/c/compare-to-zero/pylintrc
+++ /dev/null
@@ -1,2 +0,0 @@
-[main]
-load-plugins=pylint.extensions.comparetozero
diff --git a/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/bad.py b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/bad.py
new file mode 100644
index 000000000..2f93afd31
--- /dev/null
+++ b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/bad.py
@@ -0,0 +1,6 @@
+def important_math(x: int, y: int) -> None:
+ if x == 0: # [use-implicit-booleaness-not-comparison-to-zero]
+ print("x is equal to zero")
+
+ if y != 0: # [use-implicit-booleaness-not-comparison-to-zero]
+ print("y is not equal to zero")
diff --git a/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/details.rst b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/details.rst
new file mode 100644
index 000000000..670633b2a
--- /dev/null
+++ b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/details.rst
@@ -0,0 +1,3 @@
+Following this check blindly in weakly typed code base can create hard to debug issues. If the value
+can be something else that is falsey but not an ``int`` (for example ``None``, or an empty string),
+the code will not be equivalent.
diff --git a/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/good.py b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/good.py
new file mode 100644
index 000000000..feae7fe30
--- /dev/null
+++ b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/good.py
@@ -0,0 +1,6 @@
+def important_math(x: int, y: int) -> None:
+ if not x:
+ print("x is equal to zero")
+
+ if y:
+ print("y is not equal to zero")
diff --git a/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/pylintrc b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/pylintrc
new file mode 100644
index 000000000..43d8bd751
--- /dev/null
+++ b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-zero/pylintrc
@@ -0,0 +1,2 @@
+[main]
+enable=use-implicit-booleaness-not-comparison-to-zero
diff --git a/doc/user_guide/checkers/extensions.rst b/doc/user_guide/checkers/extensions.rst
index 793b3889b..f3823d715 100644
--- a/doc/user_guide/checkers/extensions.rst
+++ b/doc/user_guide/checkers/extensions.rst
@@ -10,7 +10,6 @@ Pylint provides the following optional plugins:
- :ref:`pylint.extensions.broad_try_clause`
- :ref:`pylint.extensions.check_elif`
- :ref:`pylint.extensions.code_style`
-- :ref:`pylint.extensions.comparetozero`
- :ref:`pylint.extensions.comparison_placement`
- :ref:`pylint.extensions.confusing_elif`
- :ref:`pylint.extensions.consider_refactoring_into_while_condition`
@@ -102,20 +101,6 @@ Compare-To-Empty-String checker Messages
Used when Pylint detects comparison to an empty string constant.
-.. _pylint.extensions.comparetozero:
-
-Compare-To-Zero checker
-~~~~~~~~~~~~~~~~~~~~~~~
-
-This checker is provided by ``pylint.extensions.comparetozero``.
-Verbatim name of the checker is ``compare-to-zero``.
-
-Compare-To-Zero checker Messages
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-:compare-to-zero (C2001): *"%s" can be simplified to "%s" as 0 is falsey*
- Used when Pylint detects comparison to a 0 constant.
-
-
.. _pylint.extensions.comparison_placement:
Comparison-Placement checker
diff --git a/doc/user_guide/checkers/features.rst b/doc/user_guide/checkers/features.rst
index a6b08381a..e30aff544 100644
--- a/doc/user_guide/checkers/features.rst
+++ b/doc/user_guide/checkers/features.rst
@@ -893,6 +893,8 @@ Refactoring checker Messages
Emitted when a single "return" or "return None" statement is found at the end
of function or method definition. This statement can safely be removed
because Python will implicitly return None
+:use-implicit-booleaness-not-comparison-to-zero (C1804): *"%s" can be simplified to "%s" as 0 is falsey*
+ Used when Pylint detects comparison to a 0 constant.
:use-implicit-booleaness-not-comparison (C1803): *'%s' can be simplified to '%s' as an empty %s is falsey*
Used when Pylint detects that collection literal comparison is being used to
check for emptiness; Use implicit booleaness instead of a collection classes;
diff --git a/doc/user_guide/configuration/all-options.rst b/doc/user_guide/configuration/all-options.rst
index ecdfc9ef5..8ddafa104 100644
--- a/doc/user_guide/configuration/all-options.rst
+++ b/doc/user_guide/configuration/all-options.rst
@@ -233,7 +233,7 @@ Standard Checkers
confidence = ["HIGH", "CONTROL_FLOW", "INFERENCE", "INFERENCE_FAILURE", "UNDEFINED"]
- disable = ["raw-checker-failed", "bad-inline-option", "locally-disabled", "file-ignored", "suppressed-message", "useless-suppression", "deprecated-pragma", "use-symbolic-message-instead", "consider-using-augmented-assign"]
+ disable = ["raw-checker-failed", "bad-inline-option", "locally-disabled", "file-ignored", "suppressed-message", "useless-suppression", "deprecated-pragma", "use-implicit-booleaness-not-comparison-to-zero", "use-symbolic-message-instead", "consider-using-augmented-assign"]
enable = []
diff --git a/doc/user_guide/messages/messages_overview.rst b/doc/user_guide/messages/messages_overview.rst
index 167802ae2..50f77d35e 100644
--- a/doc/user_guide/messages/messages_overview.rst
+++ b/doc/user_guide/messages/messages_overview.rst
@@ -391,7 +391,6 @@ All messages in the convention category:
convention/bad-mcs-classmethod-argument
convention/bad-mcs-method-argument
convention/compare-to-empty-string
- convention/compare-to-zero
convention/consider-iterating-dictionary
convention/consider-using-any-or-all
convention/consider-using-dict-items
@@ -433,6 +432,7 @@ All messages in the convention category:
convention/unnecessary-lambda-assignment
convention/unneeded-not
convention/use-implicit-booleaness-not-comparison
+ convention/use-implicit-booleaness-not-comparison-to-zero
convention/use-implicit-booleaness-not-len
convention/use-maxsplit-arg
convention/use-sequence-for-iteration
@@ -449,6 +449,7 @@ All renamed messages in the convention category:
:titlesonly:
convention/blacklisted-name
+ convention/compare-to-zero
convention/len-as-condition
convention/missing-docstring
convention/old-misplaced-comparison-constant
diff --git a/doc/whatsnew/fragments/6871.user_action b/doc/whatsnew/fragments/6871.user_action
new file mode 100644
index 000000000..9aceab4c1
--- /dev/null
+++ b/doc/whatsnew/fragments/6871.user_action
@@ -0,0 +1,12 @@
+* The compare to empty string checker (``pylint.extensions.emptystring``) has been removed and its checks are
+ now part of the implicit booleaness checker:
+
+ - ``compare-to-zero`` was renamed ``use-implicit-booleaness-not-comparison-to-zero``
+ and it now need to be enabled explicitly.
+ - The ``pylint.extensions.compare-to-zero`` extension no longer exists and
+ needs to be removed from the ``load-plugins`` option.
+
+This permits to make the likeness explicit and will provide better performance as they share most of their
+conditions to be raised.
+
+Refs #6871