Skip to content

Commit

Permalink
gh-36036: Fix E721 warnings for .pyx files
Browse files Browse the repository at this point in the history
    
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
  • Loading branch information
Release Manager committed Aug 12, 2023
2 parents 5b5adf1 + d57321a commit b268272
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 23 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 isinstance(base_color, 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 isinstance(base_color, Color):
# Convert Color to RGB list
base_color = [int(k*255) for k in base_color]
color_list = []
Expand Down
24 changes: 16 additions & 8 deletions src/sage/libs/coxeter3/coxeter.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ cdef class String:
sage: all([tb > ta1, tb >= ta1, tb >= tb]) # optional - coxeter3
True
"""
if type(other) != type(self):
return False
if type(other) is not type(self):
if op in (Py_LT, Py_LE, Py_GT, Py_GE):
return NotImplemented
return op == Py_NE

s = repr(self)
o = repr(other)
Expand Down Expand Up @@ -199,8 +201,10 @@ cdef class Type:
sage: all([tb > ta1, tb >= ta1, tb >= tb]) # optional - coxeter3
True
"""
if type(other) != type(self):
return False
if type(other) is not type(self):
if op in (Py_LT, Py_LE, Py_GT, Py_GE):
return NotImplemented
return op == Py_NE

s = repr(self)
o = repr(other)
Expand Down Expand Up @@ -363,8 +367,10 @@ cdef class CoxGroup(SageObject):
sage: B4 >= A5 # optional - coxeter3
True
"""
if type(other) != type(self):
return False
if type(other) is not type(self):
if op in (Py_LT, Py_LE, Py_GT, Py_GE):
return NotImplemented
return op == Py_NE

s_t = self.type()
o_t = other.type()
Expand Down Expand Up @@ -839,8 +845,10 @@ cdef class CoxGroupElement:
sage: w1 != v1 # optional - coxeter3
True
"""
if type(other) != type(self):
return False
if type(other) is not type(self):
if op in (Py_LT, Py_LE, Py_GT, Py_GE):
return NotImplemented
return op == Py_NE

s_p = self.parent_group()
o_p = other.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):
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 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 b268272

Please sign in to comment.