From 0dac5c139802842eea9c908cf7546ae49b82ac85 Mon Sep 17 00:00:00 2001 From: "John H. Palmieri" Date: Fri, 4 Aug 2023 14:08:58 -0700 Subject: [PATCH] Fix E721 warnings for .pyx files 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. --- .../dynamics/complex_dynamics/mandel_julia_helper.pyx | 4 ++-- src/sage/libs/coxeter3/coxeter.pyx | 8 ++++---- src/sage/matrix/action.pyx | 2 +- src/sage/matroids/extension.pyx | 2 +- src/sage/matroids/lean_matrix.pyx | 4 ++-- src/sage/matroids/linear_matroid.pyx | 4 ++-- src/sage/numerical/backends/generic_backend.pyx | 2 +- src/sage/rings/integer.pyx | 4 ++-- src/sage/rings/number_field/totallyreal.pyx | 6 +++--- src/sage/structure/category_object.pyx | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/sage/dynamics/complex_dynamics/mandel_julia_helper.pyx b/src/sage/dynamics/complex_dynamics/mandel_julia_helper.pyx index 62788943b09..9ee71e4f4bf 100644 --- a/src/sage/dynamics/complex_dynamics/mandel_julia_helper.pyx +++ b/src/sage/dynamics/complex_dynamics/mandel_julia_helper.pyx @@ -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 = [] @@ -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 = [] diff --git a/src/sage/libs/coxeter3/coxeter.pyx b/src/sage/libs/coxeter3/coxeter.pyx index b6444ea177d..16407eaa919 100644 --- a/src/sage/libs/coxeter3/coxeter.pyx +++ b/src/sage/libs/coxeter3/coxeter.pyx @@ -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) @@ -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) @@ -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() @@ -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() diff --git a/src/sage/matrix/action.pyx b/src/sage/matrix/action.pyx index dc057d1dce5..48bbd1159d6 100644 --- a/src/sage/matrix/action.pyx +++ b/src/sage/matrix/action.pyx @@ -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() diff --git a/src/sage/matroids/extension.pyx b/src/sage/matroids/extension.pyx index 6043b69077c..1f2cb38a65c 100644 --- a/src/sage/matroids/extension.pyx +++ b/src/sage/matroids/extension.pyx @@ -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) diff --git a/src/sage/matroids/lean_matrix.pyx b/src/sage/matroids/lean_matrix.pyx index dd312daf138..54c68e637c0 100644 --- a/src/sage/matroids/lean_matrix.pyx +++ b/src/sage/matroids/lean_matrix.pyx @@ -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 (left)._matrix_times_matrix_(right) else: return NotImplemented @@ -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 diff --git a/src/sage/matroids/linear_matroid.pyx b/src/sage/matroids/linear_matroid.pyx index 11f6b4a2656..61452e80c48 100644 --- a/src/sage/matroids/linear_matroid.pyx +++ b/src/sage/matroids/linear_matroid.pyx @@ -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) @@ -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) diff --git a/src/sage/numerical/backends/generic_backend.pyx b/src/sage/numerical/backends/generic_backend.pyx index 20eb36cbd00..547dbea951a 100644 --- a/src/sage/numerical/backends/generic_backend.pyx +++ b/src/sage/numerical/backends/generic_backend.pyx @@ -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 diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 2cd080ddafa..10e04ae6df4 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -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: diff --git a/src/sage/rings/number_field/totallyreal.pyx b/src/sage/rings/number_field/totallyreal.pyx index 5e2abb154e4..87ae68a4d59 100644 --- a/src/sage/rings/number_field/totallyreal.pyx +++ b/src/sage/rings/number_field/totallyreal.pyx @@ -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) @@ -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 @@ -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 diff --git a/src/sage/structure/category_object.pyx b/src/sage/structure/category_object.pyx index 784a09daf4c..cc65dcb7cc1 100644 --- a/src/sage/structure/category_object.pyx +++ b/src/sage/structure/category_object.pyx @@ -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))