Skip to content

Commit b268272

Browse files
author
Release Manager
committed
gh-36036: Fix E721 warnings for .pyx files Fix E721 warnings for .pyx files <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> 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. This is a followup to #36032 which dealt with .py files. <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [X] The title is concise, informative, and self-explanatory. - [X] The description explains in detail what this PR is about. - [X] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #36036 Reported by: John H. Palmieri Reviewer(s): John H. Palmieri, Matthias Köppe
2 parents 5b5adf1 + d57321a commit b268272

File tree

10 files changed

+31
-23
lines changed

10 files changed

+31
-23
lines changed

src/sage/dynamics/complex_dynamics/mandel_julia_helper.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ cpdef polynomial_mandelbrot(f, parameter=None, double x_center=0,
739739
# Take the given base color and create a list of evenly spaced
740740
# colors between the given base color and white. The number of
741741
# colors in the list depends on the variable color_num.
742-
if type(base_color) == Color:
742+
if isinstance(base_color, Color):
743743
# Convert Color to RGB list
744744
base_color = [int(k*255) for k in base_color]
745745
color_list = []
@@ -973,7 +973,7 @@ cpdef general_julia(f, double x_center=0, double y_center=0, image_width=4,
973973
# Take the given base color and create a list of evenly spaced
974974
# colors between the given base color and white. The number of
975975
# colors in the list depends on the variable color_num.
976-
if type(base_color) == Color:
976+
if isinstance(base_color, Color):
977977
# Convert Color to RGB list
978978
base_color = [int(k*255) for k in base_color]
979979
color_list = []

src/sage/libs/coxeter3/coxeter.pyx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ cdef class String:
8686
sage: all([tb > ta1, tb >= ta1, tb >= tb]) # optional - coxeter3
8787
True
8888
"""
89-
if type(other) != type(self):
90-
return False
89+
if type(other) is not type(self):
90+
if op in (Py_LT, Py_LE, Py_GT, Py_GE):
91+
return NotImplemented
92+
return op == Py_NE
9193

9294
s = repr(self)
9395
o = repr(other)
@@ -199,8 +201,10 @@ cdef class Type:
199201
sage: all([tb > ta1, tb >= ta1, tb >= tb]) # optional - coxeter3
200202
True
201203
"""
202-
if type(other) != type(self):
203-
return False
204+
if type(other) is not type(self):
205+
if op in (Py_LT, Py_LE, Py_GT, Py_GE):
206+
return NotImplemented
207+
return op == Py_NE
204208

205209
s = repr(self)
206210
o = repr(other)
@@ -363,8 +367,10 @@ cdef class CoxGroup(SageObject):
363367
sage: B4 >= A5 # optional - coxeter3
364368
True
365369
"""
366-
if type(other) != type(self):
367-
return False
370+
if type(other) is not type(self):
371+
if op in (Py_LT, Py_LE, Py_GT, Py_GE):
372+
return NotImplemented
373+
return op == Py_NE
368374

369375
s_t = self.type()
370376
o_t = other.type()
@@ -839,8 +845,10 @@ cdef class CoxGroupElement:
839845
sage: w1 != v1 # optional - coxeter3
840846
True
841847
"""
842-
if type(other) != type(self):
843-
return False
848+
if type(other) is not type(self):
849+
if op in (Py_LT, Py_LE, Py_GT, Py_GE):
850+
return NotImplemented
851+
return op == Py_NE
844852

845853
s_p = self.parent_group()
846854
o_p = other.parent_group()

src/sage/matrix/action.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ cdef class MatrixMatrixAction(MatrixMulAction):
268268
B = B.dense_matrix()
269269
else:
270270
A = A.dense_matrix()
271-
assert type(A) == type(B), (type(A), type(B))
271+
assert type(A) is type(B), (type(A), type(B))
272272
prod = A._matrix_times_matrix_(B)
273273
if A._subdivisions is not None or B._subdivisions is not None:
274274
Asubs = A.subdivisions()

src/sage/matroids/extension.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ cdef class MatroidExtensions(LinearSubclasses):
484484
"""
485485
if M.full_rank() == 0:
486486
pass
487-
if type(M) == BasisMatroid:
487+
if isinstance(M, BasisMatroid):
488488
BM = M
489489
else:
490490
BM = BasisMatroid(M)

src/sage/matroids/lean_matrix.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ cdef class LeanMatrix:
396396
cdef long i
397397
cdef LeanMatrix A
398398
if isinstance(left, LeanMatrix):
399-
if type(left) == type(right):
399+
if type(left) is type(right):
400400
return (<LeanMatrix>left)._matrix_times_matrix_(right)
401401
else:
402402
return NotImplemented
@@ -457,7 +457,7 @@ cdef class LeanMatrix:
457457
return NotImplemented
458458
if not isinstance(left, LeanMatrix) or not isinstance(right, LeanMatrix):
459459
return NotImplemented
460-
if type(left) != type(right):
460+
if type(left) is not type(right):
461461
return NotImplemented
462462
if op == Py_EQ:
463463
res = True

src/sage/matroids/linear_matroid.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4451,7 +4451,7 @@ cdef class TernaryMatroid(LinearMatroid):
44514451
"""
44524452
if certificate:
44534453
return self._is_isomorphic(other), self._isomorphism(other)
4454-
if type(other) == TernaryMatroid:
4454+
if isinstance(other, TernaryMatroid):
44554455
return self.is_field_isomorphic(other)
44564456
else:
44574457
return LinearMatroid._is_isomorphic(self, other)
@@ -6152,7 +6152,7 @@ cdef class RegularMatroid(LinearMatroid):
61526152
"""
61536153
if certificate:
61546154
return self._is_isomorphic(other), self._isomorphism(other)
6155-
if type(other) == RegularMatroid:
6155+
if isinstance(other, RegularMatroid):
61566156
return self.is_field_isomorphic(other)
61576157
else:
61586158
return LinearMatroid._is_isomorphic(self, other)

src/sage/numerical/backends/generic_backend.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ cdef class GenericBackend:
423423
sage: p.add_linear_constraint([(0, 3), (1, 2)], None, 6) # optional - Nonexistent_LP_solver
424424
sage: p.remove_constraints([0, 1]) # optional - Nonexistent_LP_solver
425425
"""
426-
if type(constraints) == int: self.remove_constraint(constraints)
426+
if isinstance(constraints, int): self.remove_constraint(constraints)
427427

428428
cdef int last = self.nrows() + 1
429429

src/sage/rings/integer.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,12 +2852,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement):
28522852
except (ValueError, TypeError):
28532853
pass
28542854

2855-
if type(m) == Integer and type(self) == Integer:
2855+
if isinstance(m, Integer):
28562856
elog = self.exact_log(m)
28572857
if elog == -sage.rings.infinity.infinity or m**elog == self:
28582858
return elog
28592859

2860-
if (type(m) == Rational and type(self) == Integer
2860+
if (isinstance(m, Rational)
28612861
and m.numer() == 1):
28622862
elog = -self.exact_log(m.denom())
28632863
if m**elog == self:

src/sage/rings/number_field/totallyreal.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def enumerate_totallyreal_fields_prim(n, B, a = [], verbose=0, return_seqs=False
292292
f_out[n_int] = 1
293293

294294
if keep_fields:
295-
if type(keep_fields) == bool:
295+
if isinstance(keep_fields, bool):
296296
keepB = pari(int(math.floor(B*math.log(B))))
297297
else:
298298
keepB = pari(keep_fields)
@@ -337,7 +337,7 @@ def enumerate_totallyreal_fields_prim(n, B, a = [], verbose=0, return_seqs=False
337337
if verbose:
338338
verb_int = 1
339339
saveout = sys.stdout
340-
if type(verbose) == str:
340+
if isinstance(verbose, str):
341341
fsock = open(verbose, 'w')
342342
sys.stdout = fsock
343343
# Else, print to screen
@@ -458,7 +458,7 @@ def enumerate_totallyreal_fields_prim(n, B, a = [], verbose=0, return_seqs=False
458458
print("Polynomials with nfdisc <= B:", counts[3])
459459
for i from 0 <= i < lenS:
460460
print(S[i])
461-
if type(verbose) == str:
461+
if isinstance(verbose, str):
462462
fsock.close()
463463
sys.stdout = saveout
464464

src/sage/structure/category_object.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ cdef class CategoryObject(SageObject):
188188
if self._category is None:
189189
self._init_category_(category)
190190
return
191-
if not (type(category) == tuple or type(category) == list):
191+
if not isinstance(category, (tuple, list)):
192192
category = [category]
193193
self._category = self._category.join([self._category]+list(category))
194194

0 commit comments

Comments
 (0)