Skip to content

Commit

Permalink
unidiomatic-typecheck is no longer emitted for in and ``not i…
Browse files Browse the repository at this point in the history
…n`` 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
  • Loading branch information
PCManticore committed Apr 27, 2020
1 parent 9a11ae2 commit 61dc477
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def get_regex(cls, name_type):
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__
Expand Down
6 changes: 0 additions & 6 deletions tests/functional/u/unidiomatic_typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,19 @@ 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
alias(42) is int # [unidiomatic-typecheck]
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
Expand Down
19 changes: 8 additions & 11 deletions tests/functional/u/unidiomatic_typecheck.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.

0 comments on commit 61dc477

Please sign in to comment.