Skip to content

Commit

Permalink
Fix E721 warnings for .pyx files
Browse files Browse the repository at this point in the history
pycodestyle reports: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`. So replace `type(x) == str` with `isinstance(x, str)`, replace `type(x) != type(y)` with `type(x) is not type(y)`, etc.
  • Loading branch information
jhpalmieri committed Aug 4, 2023
1 parent 26f5a09 commit 26204d9
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/sage/dynamics/complex_dynamics/mandel_julia_helper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ cpdef polynomial_mandelbrot(f, parameter=None, double x_center=0,
# Take the given base color and create a list of evenly spaced
# colors between the given base color and white. The number of
# colors in the list depends on the variable color_num.
if type(base_color) == Color:
if type(base_color) is Color:
# Convert Color to RGB list
base_color = [int(k*255) for k in base_color]
color_list = []
Expand Down Expand Up @@ -973,7 +973,7 @@ cpdef general_julia(f, double x_center=0, double y_center=0, image_width=4,
# Take the given base color and create a list of evenly spaced
# colors between the given base color and white. The number of
# colors in the list depends on the variable color_num.
if type(base_color) == Color:
if type(base_color) is Color:
# Convert Color to RGB list
base_color = [int(k*255) for k in base_color]
color_list = []
Expand Down
8 changes: 4 additions & 4 deletions src/sage/libs/coxeter3/coxeter.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ cdef class String:
sage: all([tb > ta1, tb >= ta1, tb >= tb]) # optional - coxeter3
True
"""
if type(other) != type(self):
if type(other) is not type(self):
return False

s = repr(self)
Expand Down Expand Up @@ -199,7 +199,7 @@ cdef class Type:
sage: all([tb > ta1, tb >= ta1, tb >= tb]) # optional - coxeter3
True
"""
if type(other) != type(self):
if type(other) is not type(self):
return False

s = repr(self)
Expand Down Expand Up @@ -363,7 +363,7 @@ cdef class CoxGroup(SageObject):
sage: B4 >= A5 # optional - coxeter3
True
"""
if type(other) != type(self):
if type(other) is not type(self):
return False

s_t = self.type()
Expand Down Expand Up @@ -839,7 +839,7 @@ cdef class CoxGroupElement:
sage: w1 != v1 # optional - coxeter3
True
"""
if type(other) != type(self):
if type(other) is not type(self):
return False

s_p = self.parent_group()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/action.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ cdef class MatrixMatrixAction(MatrixMulAction):
B = B.dense_matrix()
else:
A = A.dense_matrix()
assert type(A) == type(B), (type(A), type(B))
assert type(A) is type(B), (type(A), type(B))
prod = A._matrix_times_matrix_(B)
if A._subdivisions is not None or B._subdivisions is not None:
Asubs = A.subdivisions()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/extension.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ cdef class MatroidExtensions(LinearSubclasses):
"""
if M.full_rank() == 0:
pass
if type(M) == BasisMatroid:
if isinstance(M, BasisMatroid):
BM = M
else:
BM = BasisMatroid(M)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matroids/lean_matrix.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ cdef class LeanMatrix:
cdef long i
cdef LeanMatrix A
if isinstance(left, LeanMatrix):
if type(left) == type(right):
if type(left) is type(right):
return (<LeanMatrix>left)._matrix_times_matrix_(right)
else:
return NotImplemented
Expand Down Expand Up @@ -457,7 +457,7 @@ cdef class LeanMatrix:
return NotImplemented
if not isinstance(left, LeanMatrix) or not isinstance(right, LeanMatrix):
return NotImplemented
if type(left) != type(right):
if type(left) is not type(right):
return NotImplemented
if op == Py_EQ:
res = True
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matroids/linear_matroid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4451,7 +4451,7 @@ cdef class TernaryMatroid(LinearMatroid):
"""
if certificate:
return self._is_isomorphic(other), self._isomorphism(other)
if type(other) == TernaryMatroid:
if isinstance(other, TernaryMatroid):
return self.is_field_isomorphic(other)
else:
return LinearMatroid._is_isomorphic(self, other)
Expand Down Expand Up @@ -6152,7 +6152,7 @@ cdef class RegularMatroid(LinearMatroid):
"""
if certificate:
return self._is_isomorphic(other), self._isomorphism(other)
if type(other) == RegularMatroid:
if isinstance(other, RegularMatroid):
return self.is_field_isomorphic(other)
else:
return LinearMatroid._is_isomorphic(self, other)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/numerical/backends/generic_backend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ cdef class GenericBackend:
sage: p.add_linear_constraint([(0, 3), (1, 2)], None, 6) # optional - Nonexistent_LP_solver
sage: p.remove_constraints([0, 1]) # optional - Nonexistent_LP_solver
"""
if type(constraints) == int: self.remove_constraint(constraints)
if isinstance(constraints, int): self.remove_constraint(constraints)

cdef int last = self.nrows() + 1

Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/integer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2852,12 +2852,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement):
except (ValueError, TypeError):
pass

if type(m) == Integer and type(self) == Integer:
if isinstance(m, Integer) and isinstance(self, Integer):
elog = self.exact_log(m)
if elog == -sage.rings.infinity.infinity or m**elog == self:
return elog

if (type(m) == Rational and type(self) == Integer
if (isinstance(m, Rational) and isinstance(self, Integer)
and m.numer() == 1):
elog = -self.exact_log(m.denom())
if m**elog == self:
Expand Down
6 changes: 3 additions & 3 deletions src/sage/rings/number_field/totallyreal.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def enumerate_totallyreal_fields_prim(n, B, a = [], verbose=0, return_seqs=False
f_out[n_int] = 1

if keep_fields:
if type(keep_fields) == bool:
if isinstance(keep_fields, bool):
keepB = pari(int(math.floor(B*math.log(B))))
else:
keepB = pari(keep_fields)
Expand Down Expand Up @@ -337,7 +337,7 @@ def enumerate_totallyreal_fields_prim(n, B, a = [], verbose=0, return_seqs=False
if verbose:
verb_int = 1
saveout = sys.stdout
if type(verbose) == str:
if isinstance(verbose, str):
fsock = open(verbose, 'w')
sys.stdout = fsock
# Else, print to screen
Expand Down Expand Up @@ -458,7 +458,7 @@ def enumerate_totallyreal_fields_prim(n, B, a = [], verbose=0, return_seqs=False
print("Polynomials with nfdisc <= B:", counts[3])
for i from 0 <= i < lenS:
print(S[i])
if type(verbose) == str:
if isinstance(verbose, str):
fsock.close()
sys.stdout = saveout

Expand Down
2 changes: 1 addition & 1 deletion src/sage/structure/category_object.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ cdef class CategoryObject(SageObject):
if self._category is None:
self._init_category_(category)
return
if not (type(category) == tuple or type(category) == list):
if not isinstance(category, (tuple, list)):
category = [category]
self._category = self._category.join([self._category]+list(category))

Expand Down

0 comments on commit 26204d9

Please sign in to comment.