summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorZen Lee <53538590+zenlyj@users.noreply.github.com>2023-02-27 04:21:34 +0800
committerGitHub <noreply@github.com>2023-02-26 21:21:34 +0100
commit52a2a04a59526ce8344d4d2b7f86bb978177e047 (patch)
treed8e9053d8eca4c9eb1cce97173ef5d3a065cb750 /doc
parent27a3984832faf36be4fab07fef84086d25283846 (diff)
downloadpylint-git-52a2a04a59526ce8344d4d2b7f86bb978177e047.tar.gz
Add new checker `bad-chained-comparison` (#7990)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/data/messages/b/bad-chained-comparison/bad.py3
-rw-r--r--doc/data/messages/b/bad-chained-comparison/good.py3
-rw-r--r--doc/data/messages/b/bad-chained-comparison/related.rst1
-rw-r--r--doc/user_guide/checkers/features.rst13
-rw-r--r--doc/user_guide/messages/messages_overview.rst1
-rw-r--r--doc/whatsnew/fragments/6559.new_check4
6 files changed, 25 insertions, 0 deletions
diff --git a/doc/data/messages/b/bad-chained-comparison/bad.py b/doc/data/messages/b/bad-chained-comparison/bad.py
new file mode 100644
index 000000000..eeca75f13
--- /dev/null
+++ b/doc/data/messages/b/bad-chained-comparison/bad.py
@@ -0,0 +1,3 @@
+def xor_check(*, left=None, right=None):
+ if left is None != right is None: # [bad-chained-comparison]
+ raise ValueError('Either both left= and right= need to be provided or none should.')
diff --git a/doc/data/messages/b/bad-chained-comparison/good.py b/doc/data/messages/b/bad-chained-comparison/good.py
new file mode 100644
index 000000000..115f4a9db
--- /dev/null
+++ b/doc/data/messages/b/bad-chained-comparison/good.py
@@ -0,0 +1,3 @@
+def xor_check(*, left=None, right=None):
+ if (left is None) != (right is None):
+ raise ValueError('Either both left= and right= need to be provided or none should.')
diff --git a/doc/data/messages/b/bad-chained-comparison/related.rst b/doc/data/messages/b/bad-chained-comparison/related.rst
new file mode 100644
index 000000000..620ba6df3
--- /dev/null
+++ b/doc/data/messages/b/bad-chained-comparison/related.rst
@@ -0,0 +1 @@
+- `Comparison Chaining <https://docs.python.org/3/reference/expressions.html#comparisons>`_
diff --git a/doc/user_guide/checkers/features.rst b/doc/user_guide/checkers/features.rst
index ac17fabb6..d5bceae57 100644
--- a/doc/user_guide/checkers/features.rst
+++ b/doc/user_guide/checkers/features.rst
@@ -31,6 +31,19 @@ Async checker Messages
function. This message can't be emitted when using Python < 3.5.
+Bad-Chained-Comparison checker
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Verbatim name of the checker is ``bad-chained-comparison``.
+
+Bad-Chained-Comparison checker Messages
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+:bad-chained-comparison (W3501): *Suspicious %s-part chained comparison using semantically incompatible operators (%s)*
+ Used when there is a chained comparison where one expression is part of two
+ comparisons that belong to different semantic groups ("<" does not mean the
+ same thing as "is", chaining them in "0 < x is None" is probably a mistake).
+
+
Basic checker
~~~~~~~~~~~~~
diff --git a/doc/user_guide/messages/messages_overview.rst b/doc/user_guide/messages/messages_overview.rst
index 6c4405b42..a1962f8e0 100644
--- a/doc/user_guide/messages/messages_overview.rst
+++ b/doc/user_guide/messages/messages_overview.rst
@@ -209,6 +209,7 @@ All messages in the warning category:
warning/assert-on-tuple
warning/attribute-defined-outside-init
warning/bad-builtin
+ warning/bad-chained-comparison
warning/bad-dunder-name
warning/bad-format-string
warning/bad-format-string-key
diff --git a/doc/whatsnew/fragments/6559.new_check b/doc/whatsnew/fragments/6559.new_check
new file mode 100644
index 000000000..fa4f146e3
--- /dev/null
+++ b/doc/whatsnew/fragments/6559.new_check
@@ -0,0 +1,4 @@
+Add a ``bad-chained-comparison`` check that emits a warning when
+there is a chained comparison where one expression is semantically incompatible with the other.
+
+Closes #6559