Skip to content

Commit 1935809

Browse files
maresbricardoV94
authored andcommitted
Fix E721: do not compare types, for exact checks use is / is not
1 parent 4b6a444 commit 1935809

File tree

27 files changed

+41
-41
lines changed

27 files changed

+41
-41
lines changed

pytensor/compile/debugmode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ def _lessbroken_deepcopy(a):
687687
else:
688688
rval = copy.deepcopy(a)
689689

690-
assert type(rval) == type(a), (type(rval), type(a))
690+
assert type(rval) is type(a), (type(rval), type(a))
691691

692692
if isinstance(rval, np.ndarray):
693693
assert rval.dtype == a.dtype
@@ -1154,7 +1154,7 @@ def __str__(self):
11541154
return str(self.__dict__)
11551155

11561156
def __eq__(self, other):
1157-
rval = type(self) == type(other)
1157+
rval = type(self) is type(other)
11581158
if rval:
11591159
# nodes are not compared because this comparison is
11601160
# supposed to be true for corresponding events that happen

pytensor/compile/ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def __init__(self, fn, itypes, otypes, infer_shape):
246246
self.infer_shape = self._infer_shape
247247

248248
def __eq__(self, other):
249-
return type(self) == type(other) and self.__fn == other.__fn
249+
return type(self) is type(other) and self.__fn == other.__fn
250250

251251
def __hash__(self):
252252
return hash(type(self)) ^ hash(self.__fn)

pytensor/graph/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ def __eq__(self, other):
748748
return True
749749

750750
return (
751-
type(self) == type(other)
751+
type(self) is type(other)
752752
and self.id == other.id
753753
and self.type == other.type
754754
)

pytensor/graph/null_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def values_eq(self, a, b, force_same_dtype=True):
3333
raise ValueError("NullType has no values to compare")
3434

3535
def __eq__(self, other):
36-
return type(self) == type(other)
36+
return type(self) is type(other)
3737

3838
def __hash__(self):
3939
return hash(type(self))

pytensor/graph/rewriting/unify.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def __new__(cls, constraint, token=None, prefix=""):
5757
return obj
5858

5959
def __eq__(self, other):
60-
if type(self) == type(other):
61-
return self.token == other.token and self.constraint == other.constraint
60+
if type(self) is type(other):
61+
return self.token is other.token and self.constraint == other.constraint
6262
return NotImplemented
6363

6464
def __hash__(self):

pytensor/graph/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def __hash__(self):
229229
if "__eq__" not in dct:
230230

231231
def __eq__(self, other):
232-
return type(self) == type(other) and tuple(
232+
return type(self) is type(other) and tuple(
233233
getattr(self, a) for a in props
234234
) == tuple(getattr(other, a) for a in props)
235235

pytensor/ifelse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(self, n_outs, as_view=False, name=None):
7878
self.name = name
7979

8080
def __eq__(self, other):
81-
if type(self) != type(other):
81+
if type(self) is not type(other):
8282
return False
8383
if self.as_view != other.as_view:
8484
return False

pytensor/link/c/params_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def __hash__(self):
301301

302302
def __eq__(self, other):
303303
return (
304-
type(self) == type(other)
304+
type(self) is type(other)
305305
and self.__params_type__ == other.__params_type__
306306
and all(
307307
# NB: Params object should have been already filtered.
@@ -435,7 +435,7 @@ def __repr__(self):
435435

436436
def __eq__(self, other):
437437
return (
438-
type(self) == type(other)
438+
type(self) is type(other)
439439
and self.fields == other.fields
440440
and self.types == other.types
441441
)

pytensor/link/c/type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def __hash__(self):
515515

516516
def __eq__(self, other):
517517
return (
518-
type(self) == type(other)
518+
type(self) is type(other)
519519
and self.ctype == other.ctype
520520
and len(self) == len(other)
521521
and len(self.aliases) == len(other.aliases)

pytensor/raise_op.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class ExceptionType(Generic):
1818
def __eq__(self, other):
19-
return type(self) == type(other)
19+
return type(self) is type(other)
2020

2121
def __hash__(self):
2222
return hash(type(self))
@@ -51,7 +51,7 @@ def __str__(self):
5151
return f"CheckAndRaise{{{self.exc_type}({self.msg})}}"
5252

5353
def __eq__(self, other):
54-
if type(self) != type(other):
54+
if type(self) is not type(other):
5555
return False
5656

5757
if self.msg == other.msg and self.exc_type == other.exc_type:

0 commit comments

Comments
 (0)