diff --git a/cython/SnapPy.pxi b/cython/SnapPy.pxi index c4304d04d..4bffcd221 100644 --- a/cython/SnapPy.pxi +++ b/cython/SnapPy.pxi @@ -67,7 +67,7 @@ ELIF REAL_TYPE == 'double': double default_vertex_epsilon double det_error_epsilon cdef real_to_string(Real x): - return '%.18f'%x + return '%.18f' % x # SnapPea declarations @@ -746,7 +746,7 @@ cdef extern from "addl_code.h": extern void free_gluing_equations(int** equations, int num_rows) extern int* get_cusp_equation(c_Triangulation* manifold, int cusp_num, int m, int l, int* num_rows) extern void free_cusp_equation(int* equation) - extern c_Triangulation* triangulate_link_complement_from_file(char* file_name, char *path) except * + extern c_Triangulation* triangulate_link_complement_from_file(char* file_name, char *path) except * extern c_Triangulation* fibered_manifold_associated_to_braid(int numStrands, int braidLength, int* word) except * extern void set_tet_shapes(c_Triangulation* manifold, Complex* filled_shapes, Complex* complete_shapes) extern void set_target_holonomy(c_Triangulation* manifold, int theCuspIndex, Complex theTarget, int theRecomputeFlag) diff --git a/cython/core/abelian_group.pyx b/cython/core/abelian_group.pyx index 27cb4ac44..20f09570a 100644 --- a/cython/core/abelian_group.pyx +++ b/cython/core/abelian_group.pyx @@ -67,8 +67,8 @@ cdef class AbelianGroup(): def __repr__(self): if len(self.divisors) == 0: return '0' - factors = ( ['Z/%d'%n for n in self.divisors if n != 0] + - ['Z' for n in self.divisors if n == 0] ) + factors = (['Z/%d' % n for n in self.divisors if n] + + ['Z' for n in self.divisors if not n]) return ' + '.join(factors) def __len__(self): @@ -231,7 +231,8 @@ cdef class PresentationMatrix(): """ cdef temp, m, i, j, k, l while len(self._units) > 0: - for i,j in self._units: break + for i, j in self._units: + break col_support = [k for k in self._col_support[j] if k != i] + [i] row_entries = [(l, self._entries.get((i,l), 0)) for l in self._row_support[i]] diff --git a/cython/core/basic.pyx b/cython/core/basic.pyx index 6644e9f1e..654d22e2a 100644 --- a/cython/core/basic.pyx +++ b/cython/core/basic.pyx @@ -139,7 +139,7 @@ def to_byte_str(s): # Types of covering spaces -cover_types = {1:"irregular", 2:"regular", 3:"cyclic"} +cover_types = {1: "irregular", 2: "regular", 3: "cyclic"} # Paths manifold_path = manifold_paths[0] + os.sep @@ -179,7 +179,7 @@ cdef public void uFatalError(const_char_ptr function, # uFatalError which is usually the root cause of the problem. if not PyErr_Occurred(): raise SnapPeaFatalError('SnapPea crashed in function %s(), ' - 'defined in %s.c.'%(function, file)) + 'defined in %s.c.' % (function, file)) # Global variables used for interrupt processing cdef public Boolean gLongComputationInProgress @@ -257,7 +257,7 @@ cdef public int uQuery(const_char_ptr message, # from the user, but for now it is set up to return the default # response, to facilitate batch computations. cdef char *default = responses[ default_response] - sys.stderr.write('Q: %s\nA: %s\n'%( message, default)) + sys.stderr.write('Q: %s\nA: %s\n' % ( message, default)) return default_response diff --git a/cython/core/dirichlet.pyx b/cython/core/dirichlet.pyx index 999877653..d8719ba60 100644 --- a/cython/core/dirichlet.pyx +++ b/cython/core/dirichlet.pyx @@ -14,7 +14,7 @@ cdef (WEPolyhedron*, int) get_generators_from_bytes( '"% Generators"') nums = [] for line in data[1:]: - nums += line.split() + nums += line.split() num_gens = int(nums[0]) nums.pop(0) @@ -26,7 +26,7 @@ cdef (WEPolyhedron*, int) get_generators_from_bytes( for j in range(4): for k in range(4): num_string = nums.pop(0) # save a reference - generators[i][j][k] = Real_from_string( + generators[i][j][k] = Real_from_string( num_string) elif len(nums) == 8*num_gens: temp_gens = malloc( @@ -171,7 +171,7 @@ cdef class CDirichletDomain(): free_Dirichlet_domain(self.c_dirichlet_domain) def __repr__(self): - return '%d finite vertices, %d ideal vertices; %d edges; %d faces'%( + return '%d finite vertices, %d ideal vertices; %d edges; %d faces' % ( self.num_finite_vertices(), self.num_ideal_vertices(), self.num_edges(), @@ -500,7 +500,7 @@ cdef class CDirichletDomain(): def view(self): if PolyhedronViewer: return ViewerWindow(PolyhedronViewer, facedicts=self.face_list(), - title='Dirichlet Domain of %s'%self.manifold_name) + title='Dirichlet Domain of %s' % self.manifold_name) else: raise RuntimeError('The PolyhedronViewer class ' 'was not imported.') @@ -629,10 +629,10 @@ cdef class CDirichletDomain(): def _to_string(self): matrices = self.pairing_matrices() - result = '%% Generators\n%s\n'%len(matrices) + result = '%% Generators\n%s\n' % len(matrices) for matrix in matrices: for row in matrix: - result += ' %s\n'%' '.join([str(x) for x in row]) + result += ' %s\n' % ' '.join(str(x) for x in row) result += '\n' return result @@ -694,7 +694,8 @@ cdef class CDirichletDomain(): output = stl(self.face_list(), model, cutout, num_subdivisions, shrink_factor, cutoff_radius) with open(filename, 'w') as output_file: for line in output: - if UI_callback is not None: UI_callback() + if UI_callback is not None: + UI_callback() output_file.write(line) diff --git a/cython/core/fundamental_group.pyx b/cython/core/fundamental_group.pyx index 2cad0607a..aff19a6e4 100644 --- a/cython/core/fundamental_group.pyx +++ b/cython/core/fundamental_group.pyx @@ -121,7 +121,7 @@ cdef class CFundamentalGroup(): free_group_presentation(self.c_group_presentation) def __repr__(self): - return 'Generators:\n %s\nRelators:\n %s'%( + return 'Generators:\n %s\nRelators:\n %s' % ( ','.join(self.generators()), '\n '.join(self.relators())) diff --git a/cython/core/manifold.pyx b/cython/core/manifold.pyx index 1a5e0ca6e..9d0f07c0e 100644 --- a/cython/core/manifold.pyx +++ b/cython/core/manifold.pyx @@ -200,7 +200,8 @@ cdef class Manifold(Triangulation): cdef result cdef Triangulation new_tri - if self.c_triangulation is NULL: return "" + if self.c_triangulation is NULL: + return "" copy_triangulation(self.c_triangulation, &c_retriangulated_triangulation) @@ -649,10 +650,11 @@ cdef class Manifold(Triangulation): """ cdef int acc cdef solution_type - if self.c_triangulation is NULL: return 0 + if self.c_triangulation is NULL: + return 0 solution_type = self.solution_type() if solution_type in ('not attempted', 'no solution found'): - raise ValueError('Solution type is: %s'%solution_type) + raise ValueError('Solution type is: %s' % solution_type) IF HIGH_PRECISION is True: # must provide a start value to get the correct precision result = sum( @@ -760,7 +762,8 @@ cdef class Manifold(Triangulation): cdef Real CS cdef int accuracy - if self.c_triangulation is NULL: return 0 + if self.c_triangulation is NULL: + return 0 get_CS_value(self.c_triangulation, &is_known, &CS, @@ -888,7 +891,8 @@ cdef class Manifold(Triangulation): cdef int acc_rec_re, acc_rec_im, acc_log_re, acc_log_im cdef Boolean is_geometric - if self.c_triangulation is NULL: return [] + if self.c_triangulation is NULL: + return [] # The SnapPea kernel itself supports non-orientable manifolds, # but the extensions in snap and verify don't. @@ -1173,9 +1177,8 @@ cdef class Manifold(Triangulation): if data_spec is None: return ListOnePerLine([self.cusp_info(i) for i in range(self.num_cusps())]) - # Need to check that data_spec has string type or unicode type - # for backwards compatibility with python 2.7. - if type(data_spec) == type('') or type(data_spec) == type(u''): + # Need to check that data_spec has string type + if isinstance(data_spec, str): return [c[data_spec] for c in self.cusp_info()] cusp_index = valid_index( data_spec, self.num_cusps(), @@ -1204,8 +1207,8 @@ cdef class Manifold(Triangulation): 'shape': self._number_(shape), 'shape_accuracy': current_shape_accuracy, 'modulus': self._number_(modulus), - 'holonomies':(self._number_(meridian), self._number_(longitude)), - 'holonomy_accuracy':min(meridian_accuracy,longitude_accuracy) + 'holonomies': (self._number_(meridian), self._number_(longitude)), + 'holonomy_accuracy': min(meridian_accuracy,longitude_accuracy) } core_geodesic(self.c_triangulation, cusp_index, @@ -1215,8 +1218,8 @@ cdef class Manifold(Triangulation): core_length = Complex2Number(c_core_length) core_length.accuracy = accuracy info.update({ - 'core_length' : self._number_(core_length), - 'singularity_index':singularity_index + 'core_length': self._number_(core_length), + 'singularity_index': singularity_index }) return CuspInfo(**info) @@ -1498,7 +1501,7 @@ cdef class Manifold(Triangulation): max_segments = which_curve.max_segments which_curve = which_curve.index - new_name = to_byte_str(self.name() + '-%d'%which_curve) + new_name = to_byte_str(self.name() + '-%d' % which_curve) c_new_name = new_name dual_curves(self.c_triangulation, @@ -1627,7 +1630,8 @@ cdef class Manifold(Triangulation): cdef long int p, q cdef c_Triangulation *c_canonized_triangulation - if self.c_triangulation is NULL: return False + if self.c_triangulation is NULL: + return False copy_triangulation(self.c_triangulation, &c_canonized_triangulation) proto_canonize(c_canonized_triangulation) @@ -1666,18 +1670,18 @@ cdef class Manifold(Triangulation): &perm0, &perm1, &perm2, &perm3) ans.append( {'index':i, - 'generators':(face0_gen, face1_gen, face2_gen, face3_gen), - 'neighbors':(neighbor0_idx, neighbor1_idx, - neighbor2_idx, neighbor3_idx), - 'gluings': ( tuple([ perm0>>(2 * i) & 3 for i in range(4)]), - tuple([ perm1>>(2 * i) & 3 for i in range(4)]), - tuple([ perm2>>(2 * i) & 3 for i in range(4)]), - tuple([ perm3>>(2 * i) & 3 for i in range(4)])), - 'corners': ( self._number_(Complex2Number(c0)), - self._number_(Complex2Number(c1)), - self._number_(Complex2Number(c2)), - self._number_(Complex2Number(c3)) ), - 'generator_path':generator_path} + 'generators': (face0_gen, face1_gen, face2_gen, face3_gen), + 'neighbors': (neighbor0_idx, neighbor1_idx, + neighbor2_idx, neighbor3_idx), + 'gluings': (tuple([ perm0>>(2 * i) & 3 for i in range(4)]), + tuple([ perm1>>(2 * i) & 3 for i in range(4)]), + tuple([ perm2>>(2 * i) & 3 for i in range(4)]), + tuple([ perm3>>(2 * i) & 3 for i in range(4)])), + 'corners': (self._number_(Complex2Number(c0)), + self._number_(Complex2Number(c1)), + self._number_(Complex2Number(c2)), + self._number_(Complex2Number(c3)) ), + 'generator_path': generator_path} ) return ans @@ -1754,7 +1758,7 @@ cdef class Manifold(Triangulation): cdef NormalSurfaceList *surfaces cdef c_FuncResult result cdef int num_surfaces - cdef c_Triangulation *pieces[2] + cdef c_Triangulation *pieces[2] cdef Manifold M0, M1 if self.c_triangulation is NULL: @@ -1771,7 +1775,7 @@ cdef class Manifold(Triangulation): if not (0 <= which_surface < num_surfaces): raise ValueError('SnapPea only found %d surfaces, but you asked for surface number %s.' % (num_surfaces, which_surface)) - result = split_along_normal_surface(surfaces, which_surface, pieces) + result = split_along_normal_surface(surfaces, which_surface, pieces) if result != func_OK: raise RuntimeError('SnapPea kernel failed when splitting open along the given surface.') diff --git a/cython/core/triangulation.pyx b/cython/core/triangulation.pyx index 53dcef428..7d9e54d31 100644 --- a/cython/core/triangulation.pyx +++ b/cython/core/triangulation.pyx @@ -229,7 +229,7 @@ cdef class Triangulation(): knot = spherogram.DTcodec(DT) c_triangulation = get_triangulation_from_PythonKLP( knot.KLPProjection(), remove_finite_vertices) - name = to_byte_str('%d'%crossings + alternation + '%d'%index) + name = to_byte_str('%d' % crossings + alternation + '%d' % index) set_triangulation_name(c_triangulation, name) self._set_DTcode(knot) self.set_c_triangulation(c_triangulation) @@ -432,9 +432,11 @@ cdef class Triangulation(): False """ orientability = Orientability[get_orientability(self.c_triangulation)] - if orientability == 'orientable': return True - elif orientability == 'nonorientable': return False - else: return None + if orientability == 'orientable': + return True + if orientability == 'nonorientable': + return False + return None def copy(self): """ @@ -685,7 +687,7 @@ cdef class Triangulation(): _to_string. """ cdef c_Triangulation* c_triangulation = NULL - if not self.c_triangulation is NULL: + if self.c_triangulation is not NULL: raise ValueError('The Triangulation must be empty.') b_string = to_byte_str(string) c_triangulation = read_triangulation_from_string(b_string) @@ -719,7 +721,7 @@ cdef class Triangulation(): if c_terse.glues_to_old_tet[n]: byte |= 1 << bit bit += 1 - if bit%8 == 0: + if bit % 8 == 0: byteseq.append(byte) byte, bit = 0, 0 if bit: @@ -745,7 +747,7 @@ cdef class Triangulation(): True """ cdef c_Triangulation* c_triangulation = NULL - if not self.c_triangulation is NULL: + if self.c_triangulation is not NULL: raise ValueError('The Triangulation must be empty.') c_triangulation = triangulation_from_bytes(bytestring) self.set_c_triangulation(c_triangulation) @@ -754,7 +756,7 @@ cdef class Triangulation(): """ """ cdef c_Triangulation* c_triangulation = NULL - if not self.c_triangulation is NULL: + if self.c_triangulation is not NULL: raise ValueError('The Triangulation must be empty.') c_triangulation = unpickle_triangulation(bytestring) self.set_c_triangulation(c_triangulation) @@ -804,7 +806,7 @@ cdef class Triangulation(): True """ cdef c_Triangulation* c_triangulation = NULL - if not self.c_triangulation is NULL: + if self.c_triangulation is not NULL: raise ValueError('The Triangulation must be empty.') c_triangulation = listlike_to_triangulation(tetrahedra_data, num_or_cusps, @@ -831,7 +833,7 @@ cdef class Triangulation(): triangulation_isosig. """ - if not self.c_triangulation is NULL: + if self.c_triangulation is not NULL: raise ValueError('The Triangulation must be empty.') match = is_decorated_isosig.match(isosig) @@ -1051,7 +1053,8 @@ cdef class Triangulation(): >>> M.name() '4_1' """ - if self.c_triangulation is NULL: return + if self.c_triangulation is NULL: + return return to_str(get_triangulation_name(self.c_triangulation)) def set_name(self, new_name): @@ -1117,7 +1120,8 @@ cdef class Triangulation(): >>> M.num_tetrahedra() 2 """ - if self.c_triangulation is NULL: return 0 + if self.c_triangulation is NULL: + return 0 return get_num_tetrahedra(self.c_triangulation) def dehn_fill(self, filling_data, which_cusp=None): @@ -1226,7 +1230,7 @@ cdef class Triangulation(): if data_spec is None: return ListOnePerLine([self.cusp_info(i) for i in range(self.num_cusps())]) - if type(data_spec) == type(''): + if isinstance(data_spec, str): return [c[data_spec] for c in self.cusp_info()] cusp_index = valid_index( data_spec, self.num_cusps(),