summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2020-04-27 09:49:37 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2020-04-27 10:12:54 +0200
commitdb0d55bcb19db4d8a9b7dd339d6ab554a4a1f017 (patch)
tree9f554e6d17948509bd8d4ce3cecaf090db663772
parentbbe21518374be8700ee2bb6b26557a5377145771 (diff)
downloadpylint-git-db0d55bcb19db4d8a9b7dd339d6ab554a4a1f017.tar.gz
``unidiomatic-typecheck`` is no longer emitted for ``in`` and ``not in`` operators
The original use case for this check was to catch old style type checking idioms such as `type(x) is ...`, but it should not have been extended to handle `in` operators as well. Close #3337
-rw-r--r--ChangeLog4
-rw-r--r--pylint/checkers/base.py2
-rw-r--r--tests/functional/u/unidiomatic_typecheck.py6
-rw-r--r--tests/functional/u/unidiomatic_typecheck.txt19
4 files changed, 13 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 3ed3e66da..f8d322ef6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -26,6 +26,10 @@ Release date: TBA
* Positional-only arguments are taken in account for ``useless-super-delegation``
+* ``unidiomatic-typecheck`` is no longer emitted for ``in`` and ``not in`` operators
+
+ Close #3337
+
* Positional-only argument annotations are taken in account for ``unused-import``
Close #3462
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py
index f5117ed0e..ed22ff443 100644
--- a/pylint/checkers/base.py
+++ b/pylint/checkers/base.py
@@ -152,7 +152,7 @@ NO_REQUIRED_DOC_RGX = re.compile("^_")
REVERSED_PROTOCOL_METHOD = "__reversed__"
SEQUENCE_PROTOCOL_METHODS = ("__getitem__", "__len__")
REVERSED_METHODS = (SEQUENCE_PROTOCOL_METHODS, (REVERSED_PROTOCOL_METHOD,))
-TYPECHECK_COMPARISON_OPERATORS = frozenset(("is", "is not", "==", "!=", "in", "not in"))
+TYPECHECK_COMPARISON_OPERATORS = frozenset(("is", "is not", "==", "!="))
LITERAL_NODE_TYPES = (astroid.Const, astroid.Dict, astroid.List, astroid.Set)
UNITTEST_CASE = "unittest.case"
BUILTINS = builtins.__name__
diff --git a/tests/functional/u/unidiomatic_typecheck.py b/tests/functional/u/unidiomatic_typecheck.py
index 008456b1e..302bcc2b7 100644
--- a/tests/functional/u/unidiomatic_typecheck.py
+++ b/tests/functional/u/unidiomatic_typecheck.py
@@ -6,8 +6,6 @@ def simple_positives():
type(42) is not int # [unidiomatic-typecheck]
type(42) == int # [unidiomatic-typecheck]
type(42) != int # [unidiomatic-typecheck]
- type(42) in [int] # [unidiomatic-typecheck]
- type(42) not in [int] # [unidiomatic-typecheck]
def simple_inference_positives():
alias = type
@@ -15,16 +13,12 @@ def simple_inference_positives():
alias(42) is not int # [unidiomatic-typecheck]
alias(42) == int # [unidiomatic-typecheck]
alias(42) != int # [unidiomatic-typecheck]
- alias(42) in [int] # [unidiomatic-typecheck]
- alias(42) not in [int] # [unidiomatic-typecheck]
def type_creation_negatives():
type('Q', (object,), dict(a=1)) is int
type('Q', (object,), dict(a=1)) is not int
type('Q', (object,), dict(a=1)) == int
type('Q', (object,), dict(a=1)) != int
- type('Q', (object,), dict(a=1)) in [int]
- type('Q', (object,), dict(a=1)) not in [int]
def invalid_type_call_negatives(**kwargs):
type(bad=7) is int
diff --git a/tests/functional/u/unidiomatic_typecheck.txt b/tests/functional/u/unidiomatic_typecheck.txt
index 23c0f6f28..65f2aa59e 100644
--- a/tests/functional/u/unidiomatic_typecheck.txt
+++ b/tests/functional/u/unidiomatic_typecheck.txt
@@ -3,16 +3,13 @@ unidiomatic-typecheck:6:simple_positives:Using type() instead of isinstance() fo
unidiomatic-typecheck:7:simple_positives:Using type() instead of isinstance() for a typecheck.
unidiomatic-typecheck:8:simple_positives:Using type() instead of isinstance() for a typecheck.
unidiomatic-typecheck:9:simple_positives:Using type() instead of isinstance() for a typecheck.
-unidiomatic-typecheck:10:simple_positives:Using type() instead of isinstance() for a typecheck.
+unidiomatic-typecheck:12:simple_inference_positives:Using type() instead of isinstance() for a typecheck.
+unidiomatic-typecheck:13:simple_inference_positives:Using type() instead of isinstance() for a typecheck.
unidiomatic-typecheck:14:simple_inference_positives:Using type() instead of isinstance() for a typecheck.
unidiomatic-typecheck:15:simple_inference_positives:Using type() instead of isinstance() for a typecheck.
-unidiomatic-typecheck:16:simple_inference_positives:Using type() instead of isinstance() for a typecheck.
-unidiomatic-typecheck:17:simple_inference_positives:Using type() instead of isinstance() for a typecheck.
-unidiomatic-typecheck:18:simple_inference_positives:Using type() instead of isinstance() for a typecheck.
-unidiomatic-typecheck:19:simple_inference_positives:Using type() instead of isinstance() for a typecheck.
-unidiomatic-typecheck:71:type_of_literals_positives:Using type() instead of isinstance() for a typecheck.
-unidiomatic-typecheck:72:type_of_literals_positives:Using type() instead of isinstance() for a typecheck.
-unidiomatic-typecheck:73:type_of_literals_positives:Using type() instead of isinstance() for a typecheck.
-unidiomatic-typecheck:74:type_of_literals_positives:Using type() instead of isinstance() for a typecheck.
-unidiomatic-typecheck:75:type_of_literals_positives:Using type() instead of isinstance() for a typecheck.
-unidiomatic-typecheck:76:type_of_literals_positives:Using type() instead of isinstance() for a typecheck. \ No newline at end of file
+unidiomatic-typecheck:65:type_of_literals_positives:Using type() instead of isinstance() for a typecheck.
+unidiomatic-typecheck:66:type_of_literals_positives:Using type() instead of isinstance() for a typecheck.
+unidiomatic-typecheck:67:type_of_literals_positives:Using type() instead of isinstance() for a typecheck.
+unidiomatic-typecheck:68:type_of_literals_positives:Using type() instead of isinstance() for a typecheck.
+unidiomatic-typecheck:69:type_of_literals_positives:Using type() instead of isinstance() for a typecheck.
+unidiomatic-typecheck:70:type_of_literals_positives:Using type() instead of isinstance() for a typecheck.