Repository: pylint-dev/pylint

Issue:
unidiomatic-typecheck only checks left-hand side
### Bug description

```python
# pylint: disable=missing-module-docstring, expression-not-assigned
type(1) == int
int == type(1)
```


### Pylint output

```python
************* Module a
a.py:2:0: C0123: Use isinstance() rather than type() for a typecheck. (unidiomatic-typecheck)
```

### Expected behavior
```python
************* Module a
a.py:2:0: C0123: Use isinstance() rather than type() for a typecheck. (unidiomatic-typecheck)
a.py:3:0: C0123: Use isinstance() rather than type() for a typecheck. (unidiomatic-typecheck)
```

### Pylint version

```shell
pylint 4.0.0-dev0
astroid 4.0.0-dev0
Python 3.13.1 (v3.13.1:06714517797, Dec  3 2024, 14:00:22) [Clang 15.0.0 (clang-1500.3.9.4)]
```

### OS / Environment

_No response_

### Additional dependencies

```python

```


Discussion:
nice one 👍,  i recall seeing this as well when triaging a separate `unidiomatic-typecheck` issue
Hi @jacobtylerwalls 
I have raised a PR for fixing this issue. Your feedback would be very helpful. Thank you!



Patch:
diff --git a/doc/whatsnew/fragments/10217.bugfix b/doc/whatsnew/fragments/10217.bugfix
new file mode 100644
index 0000000000..d498dc0749
--- /dev/null
+++ b/doc/whatsnew/fragments/10217.bugfix
@@ -0,0 +1,3 @@
+Fixed unidiomatic-typecheck only checking left-hand side.
+
+Closes #10217
diff --git a/pylint/checkers/base/comparison_checker.py b/pylint/checkers/base/comparison_checker.py
index 6fb053e2e1..353f74383e 100644
--- a/pylint/checkers/base/comparison_checker.py
+++ b/pylint/checkers/base/comparison_checker.py
@@ -324,6 +324,10 @@ def _check_unidiomatic_typecheck(self, node: nodes.Compare) -> None:
             left = node.left
             if _is_one_arg_pos_call(left):
                 self._check_type_x_is_y(node, left, operator, right)
+            elif isinstance(left, nodes.Name) and _is_one_arg_pos_call(right):
+                self._check_type_x_is_y(
+                    node=node, left=right, operator=operator, right=left
+                )  # transforming Y == type(x) case to type(x) == Y
 
     def _check_type_x_is_y(
         self,


Test patch:
diff --git a/tests/functional/u/unidiomatic_typecheck.py b/tests/functional/u/unidiomatic_typecheck.py
index 2a1957d75e..1a87280cae 100644
--- a/tests/functional/u/unidiomatic_typecheck.py
+++ b/tests/functional/u/unidiomatic_typecheck.py
@@ -6,6 +6,10 @@ def simple_positives():
     type(42) is not int # [unidiomatic-typecheck]
     type(42) == int # [unidiomatic-typecheck]
     type(42) != int # [unidiomatic-typecheck]
+    int is type(42) # [unidiomatic-typecheck]
+    int is not type(42) # [unidiomatic-typecheck]
+    int == type(42) # [unidiomatic-typecheck]
+    int != type(42) # [unidiomatic-typecheck]
 
 def simple_inference_positives():
     alias = type
diff --git a/tests/functional/u/unidiomatic_typecheck.txt b/tests/functional/u/unidiomatic_typecheck.txt
index 84f5021d96..5916407bd9 100644
--- a/tests/functional/u/unidiomatic_typecheck.txt
+++ b/tests/functional/u/unidiomatic_typecheck.txt
@@ -2,13 +2,17 @@ unidiomatic-typecheck:5:4:5:19:simple_positives:Use isinstance() rather than typ
 unidiomatic-typecheck:6:4:6:23:simple_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
 unidiomatic-typecheck:7:4:7:19:simple_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
 unidiomatic-typecheck:8:4:8:19:simple_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
-unidiomatic-typecheck:12:4:12:20:simple_inference_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
-unidiomatic-typecheck:13:4:13:24:simple_inference_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
-unidiomatic-typecheck:14:4:14:20:simple_inference_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
-unidiomatic-typecheck:15:4:15:20:simple_inference_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
-unidiomatic-typecheck:65:4:65:23:type_of_literals_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
-unidiomatic-typecheck:66:4:66:27:type_of_literals_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
-unidiomatic-typecheck:67:4:67:23:type_of_literals_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
-unidiomatic-typecheck:68:4:68:27:type_of_literals_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
+unidiomatic-typecheck:9:4:9:19:simple_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
+unidiomatic-typecheck:10:4:10:23:simple_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
+unidiomatic-typecheck:11:4:11:19:simple_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
+unidiomatic-typecheck:12:4:12:19:simple_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
+unidiomatic-typecheck:16:4:16:20:simple_inference_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
+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:69:4:69:23:type_of_literals_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
 unidiomatic-typecheck:70:4:70:27:type_of_literals_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
+unidiomatic-typecheck:71:4:71:23:type_of_literals_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
+unidiomatic-typecheck:72:4:72:27:type_of_literals_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
+unidiomatic-typecheck:73:4:73:23:type_of_literals_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED
+unidiomatic-typecheck:74:4:74:27:type_of_literals_positives:Use isinstance() rather than type() for a typecheck.:UNDEFINED