diff --git a/doc/whatsnew/fragments/10365.bugfix b/doc/whatsnew/fragments/10365.bugfix new file mode 100644 index 0000000000..d4c6621d89 --- /dev/null +++ b/doc/whatsnew/fragments/10365.bugfix @@ -0,0 +1,3 @@ +Fixed unidiomatic-typecheck not flagged for type(x) is type(y). + +Closes #10365 diff --git a/pylint/checkers/base/comparison_checker.py b/pylint/checkers/base/comparison_checker.py index a2c5b10f11..543c3bb403 100644 --- a/pylint/checkers/base/comparison_checker.py +++ b/pylint/checkers/base/comparison_checker.py @@ -338,15 +338,4 @@ def _check_type_x_is_y( ): return - if _is_one_arg_pos_call(right): - right_func = utils.safe_infer(right.func) - if ( - isinstance(right_func, nodes.ClassDef) - and right_func.qname() == TYPE_QNAME - ): - # type(x) == type(a) - right_arg = utils.safe_infer(right.args[0]) - if not isinstance(right_arg, LITERAL_NODE_TYPES): - # not e.g. type(x) == type([]) - return self.add_message("unidiomatic-typecheck", node=node) diff --git a/tests/functional/u/unidiomatic_typecheck.py b/tests/functional/u/unidiomatic_typecheck.py index 784668b8a6..a488e6dfad 100644 --- a/tests/functional/u/unidiomatic_typecheck.py +++ b/tests/functional/u/unidiomatic_typecheck.py @@ -63,14 +63,14 @@ def parameter_shadowing_inference_negatives(type): def deliberate_subclass_check_negatives(a, b): - type(42) is type(b) - type(42) is not type(b) - type(42) == type(b) - type(42) != type(b) - type(a) is type(b) - type(a) is not type(b) - type(a) == type(b) - type(a) != type(b) + type(42) is type(b) # [unidiomatic-typecheck] + type(42) is not type(b) # [unidiomatic-typecheck] + type(42) == type(b) # [unidiomatic-typecheck] + type(42) != type(b) # [unidiomatic-typecheck] + type(a) is type(b) # [unidiomatic-typecheck] + type(a) is not type(b) # [unidiomatic-typecheck] + type(a) == type(b) # [unidiomatic-typecheck] + type(a) != type(b) # [unidiomatic-typecheck] def type_of_literals_positives(a): diff --git a/tests/functional/u/unidiomatic_typecheck.txt b/tests/functional/u/unidiomatic_typecheck.txt index 76369310a6..1259c142ca 100644 --- a/tests/functional/u/unidiomatic_typecheck.txt +++ b/tests/functional/u/unidiomatic_typecheck.txt @@ -10,6 +10,14 @@ unidiomatic-typecheck:16:4:16:20:simple_inference_positives:Use isinstance() rat unidiomatic-typecheck:17:4:17:24:simple_inference_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED unidiomatic-typecheck:18:4:18:20:simple_inference_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED unidiomatic-typecheck:19:4:19:20:simple_inference_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED +unidiomatic-typecheck:66:4:66:23:deliberate_subclass_check_negatives:Use isinstance() rather than type() for a typecheck.:UNDEFINED +unidiomatic-typecheck:67:4:67:27:deliberate_subclass_check_negatives:Use isinstance() rather than type() for a typecheck.:UNDEFINED +unidiomatic-typecheck:68:4:68:23:deliberate_subclass_check_negatives:Use isinstance() rather than type() for a typecheck.:UNDEFINED +unidiomatic-typecheck:69:4:69:23:deliberate_subclass_check_negatives:Use isinstance() rather than type() for a typecheck.:UNDEFINED +unidiomatic-typecheck:70:4:70:22:deliberate_subclass_check_negatives:Use isinstance() rather than type() for a typecheck.:UNDEFINED +unidiomatic-typecheck:71:4:71:26:deliberate_subclass_check_negatives:Use isinstance() rather than type() for a typecheck.:UNDEFINED +unidiomatic-typecheck:72:4:72:22:deliberate_subclass_check_negatives:Use isinstance() rather than type() for a typecheck.:UNDEFINED +unidiomatic-typecheck:73:4:73:22:deliberate_subclass_check_negatives:Use isinstance() rather than type() for a typecheck.:UNDEFINED unidiomatic-typecheck:77:4:77:23:type_of_literals_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED unidiomatic-typecheck:78:4:78:27:type_of_literals_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED unidiomatic-typecheck:79:4:79:23:type_of_literals_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED