Skip to content

Commit

Permalink
use ruff --fix --select C4 python/ (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton authored Oct 31, 2023
1 parent 3408c35 commit 40fd318
Show file tree
Hide file tree
Showing 26 changed files with 55 additions and 59 deletions.
2 changes: 1 addition & 1 deletion python/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def main():
terminal = SnapPyTerm()
sys.stdout = terminal
set_icon(terminal.window)
SnapPy_ns = dict([(x, getattr(snappy, x)) for x in snappy.__all__])
SnapPy_ns = {x: getattr(snappy, x) for x in snappy.__all__}
# SnapPy_ns['kernel_server'] = kernel_server
SnapPy_ns['exit'] = SnapPy_ns['quit'] = SnapPyExit()
SnapPy_ns['pager'] = None
Expand Down
6 changes: 3 additions & 3 deletions python/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(self, table='', db_path=None,
def _set_schema(self):
cursor, table = self._cursor, self._table
rows = cursor.execute("pragma table_info('%s')" % table).fetchall()
self.schema = dict([(row[1], row[2].lower()) for row in rows])
self.schema = {row[1]: row[2].lower() for row in rows}

def _check_schema(self):
assert (self.schema['name'] == 'text' and
Expand Down Expand Up @@ -431,7 +431,7 @@ def add_tables_from_package(package_name, must_succeed=True):
package = importlib.import_module(package_name)
except ImportError:
if not must_succeed:
return dict()
return {}
else:
raise ImportError('ManifoldTable package %s not found'
% package_name)
Expand All @@ -446,7 +446,7 @@ def add_tables_from_package(package_name, must_succeed=True):
# We also store the tables here so that their doctests can be
# checked.
if not hasattr(this_module, '__test__'):
this_module.__test__ = dict()
this_module.__test__ = {}
for name, table in new_tables.items():
this_module.__test__[name] = table.__class__

Expand Down
2 changes: 1 addition & 1 deletion python/decorated_isosig.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
in_one = string.ascii_lowercase[:16] + string.ascii_lowercase[1:16].upper()

int_to_letter = dict(enumerate(base64_letters))
letter_to_int = dict((a, i) for i, a in enumerate(base64_letters))
letter_to_int = {a: i for i, a in enumerate(base64_letters)}


def encode_nonnegative_int(x):
Expand Down
4 changes: 2 additions & 2 deletions python/drilling/cusps.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def index_geodesics_and_add_post_drill_infos(
geodesics : Sequence[GeodesicInfo],
mcomplex : Mcomplex) -> None:

all_reindexed_verts = set(
g.core_curve_cusp for g in geodesics if g.core_curve_cusp)
all_reindexed_verts = {
g.core_curve_cusp for g in geodesics if g.core_curve_cusp}

old_vertices = [v for v in mcomplex.Vertices
if v not in all_reindexed_verts]
Expand Down
6 changes: 2 additions & 4 deletions python/drilling/moves.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ def one_four_move(given_pieces : Sequence[GeodesicPiece],
new_tets : dict[int, Tetrahedron] = {
f : Tetrahedron() for f in simplex.TwoSubsimplices }

neighbors : dict[int, Tetrahedron] = {
f: t for f, t in tet.Neighbor.items() }
gluings : dict[int, Perm4] = {
f: p for f, p in tet.Gluing.items() }
neighbors : dict[int, Tetrahedron] = dict(tet.Neighbor.items())
gluings : dict[int, Perm4] = dict(tet.Gluing.items())

id_matrix = matrix.identity(ring=RF, n=4)

Expand Down
2 changes: 1 addition & 1 deletion python/exterior_to_link/barycentric_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def info(self):

class TetrahedronEmbeddingCache():
def __init__(self):
self.cache = dict()
self.cache = {}

def __call__(self, arrow, vertex_images, bdry_map=None):
if bdry_map is None:
Expand Down
2 changes: 1 addition & 1 deletion python/exterior_to_link/mcomplex_with_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def straighten_arcs(arcs):
# keep track of where we most recently had success.
offset = 0
# We also keep track of arcs obstructing a given triangle
obstructions = dict()
obstructions = {}
# Every success reduces the number of arcs by one, so
# terminates.
while success:
Expand Down
2 changes: 1 addition & 1 deletion python/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __setitem__(self, key, value):
self.data[key] = value

def entries(self):
return [ x for x in self.data ]
return list(self.data)

def list(self):
return self.entries()
Expand Down
4 changes: 2 additions & 2 deletions python/ptolemy/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,9 @@ def quotient(x, y):
Mcopy = M.copy()

return Flattenings(
dict([ (k, (log + PiI * p, z, p))
{k: (log + PiI * p, z, p)
for k, log, z, p in zip(keys, log_all_cross_ratios,
all_cross_ratios, flattenings)]),
all_cross_ratios, flattenings)},
manifold_thunk=lambda : Mcopy)

def get_order(self):
Expand Down
6 changes: 3 additions & 3 deletions python/ptolemy/findLoops.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ def _compute_point_to_shortest_path(point_identification_dict, origin,
# this property. It maps all triples equivalent to pt to path.

def identified_points_to_path(pt, path):
return dict(
[ (identified_pt, path)
for identified_pt in point_identification_dict[pt] ] )
return {
identified_pt: path
for identified_pt in point_identification_dict[pt] }

# Trivial paths for points identified with origin
previously_added = identified_points_to_path(origin, Path())
Expand Down
2 changes: 1 addition & 1 deletion python/ptolemy/ptolemyVariety.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def __init__(self, manifold, N, obstruction_class,
N, manifold.num_tetrahedra(),
isinstance(obstruction_class, PtolemyObstructionClass)))

self.equations = [eqn for eqn in self._ptolemy_relations]
self.equations = list(self._ptolemy_relations)

order_of_u = 1

Expand Down
2 changes: 1 addition & 1 deletion python/ptolemy/rur.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def subtract_denominator_from_list(polymod, exponent, l):
return

def term_to_expand_fraction_by(old_terms):
result = [ pair for pair in new_denominator_terms ]
result = list(new_denominator_terms)
for p, e in old_terms:
if e < 0:
subtract_denominator_from_list(p, e, result)
Expand Down
10 changes: 5 additions & 5 deletions python/ptolemy/solutionsToPrimeIdealGroebnerBasis.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def substitute(poly):
[eval_monomial(m) for m in poly.get_monomials()],
pari(0))

new_assignments = dict([(key, substitute(poly))
for key, poly in assignments.items()])
new_assignments = {key: substitute(poly)
for key, poly in assignments.items()}

# Merge all the assignments of variables
new_assignments.update(d)
Expand Down Expand Up @@ -227,9 +227,9 @@ def _process_extensions(extensions):
# The new number field is again in x but the assignments
# are assigning polynomials in the old x.
# Need to update.
ext_assignments = dict(
[(key, poly.substitute({'x' : old_x_in_new_x}))
for key, poly in ext_assignments.items()])
ext_assignments = {
key: poly.substitute({'x' : old_x_in_new_x})
for key, poly in ext_assignments.items()}

# And compute what the root of the last polynomial was
# to assign it.
Expand Down
2 changes: 1 addition & 1 deletion python/ptolemy/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def testGeometricRep(compute_solutions):
sol['c_0011_2']

assert any(
[ abs(vol - 2.9441064867) < 1e-9 for vol in sol.volume_numerical()])
abs(vol - 2.9441064867) < 1e-9 for vol in sol.volume_numerical())


def testSageCommandLine():
Expand Down
6 changes: 2 additions & 4 deletions python/raytracing/ideal_raytracing_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,10 @@ def _add_O13_matrices_to_faces(self):

def _add_complex_vertices(self):
for tet in self.mcomplex.Tetrahedra:
tet.complex_vertices = {
v : vert
for v, vert in zip(
tet.complex_vertices = dict(zip(
t3m.ZeroSubsimplices,
symmetric_vertices_for_tetrahedron(
tet.ShapeParameters[t3m.E01])) }
tet.ShapeParameters[t3m.E01])))

def _add_R13_vertices(self):
for tet in self.mcomplex.Tetrahedra:
Expand Down
2 changes: 1 addition & 1 deletion python/sage_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def print_results(module, results):
results.attempted))


def doctest_modules(modules, verbose=False, print_info=True, extraglobs=dict()):
def doctest_modules(modules, verbose=False, print_info=True, extraglobs={}):
finder = doctest.DocTestFinder(parser=DocTestParser())
# full_extraglobals = dict(globs.items() + extraglobs.items())
full_extraglobals = globs.copy()
Expand Down
2 changes: 1 addition & 1 deletion python/snap/peripheral/dual_cellulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DualCellulation():
"""
def __init__(self, triangulation):
self.dual_triangulation = triangulation
self.from_original = dict()
self.from_original = {}
self.vertices = []
self.edges = []
self.faces = []
Expand Down
6 changes: 3 additions & 3 deletions python/snap/peripheral/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, sides=None, vertices=None):
self.index = None

def glued_to(self, side):
for sides in ( [S for S in self.sides], [-S for S in self.sides] ):
for sides in ( list(self.sides), [-S for S in self.sides] ):
if side in sides:
sides.remove(side)
return sides[0]
Expand Down Expand Up @@ -83,7 +83,7 @@ class EdgeList():
vertex.
"""
def __init__(self, items):
self.data = dict()
self.data = {}
for i, x in enumerate(items):
self[i] = x

Expand Down Expand Up @@ -237,7 +237,7 @@ def build_vertices(self):
vertices.append(V)

self.vertices = vertices
self._vertex_containing_corner = dict([( (C.triangle, C.vertex), V) for V in vertices for C in V.corners])
self._vertex_containing_corner = {(C.triangle, C.vertex): V for V in vertices for C in V.corners}

def build(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion python/snap/peripheral/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def verbose():
def doctest_globals(module):
if hasattr(module, 'doctest_globals'):
return module.doctest_globals()
return dict()
return {}


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions python/snap/slice_obs_HKL.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(self, generators, relators, image_ring, matrices):
assert set(matrices) == set(all_gens)
else:
assert len(generators) == len(matrices)
images = dict()
images = {}
for g, m in zip(generators, matrices):
images[g] = m
images[g.swapcase()] = image_ring(m.inverse())
Expand Down Expand Up @@ -347,7 +347,7 @@ def induced_rep_from_twisted_cocycle(p, rho, chi, cocycle):
t = R.gen()
MatSp = MatrixSpace(R, p)
gens = rho.generators
images = dict()
images = {}
for s, g in enumerate(gens):
v = vector(cocycle[s*n:(s+1)*n])
e = rho.epsilon(g)[0]
Expand Down
6 changes: 3 additions & 3 deletions python/snap/t3mlite/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

# For speed, we create a lookup table for all possible gluing permutations

_arrow_gluing_dict = dict()
_arrow_gluing_dict = {}
for edge0, face0 in EdgeFacePairs:
for edge1, face1 in EdgeFacePairs:
perm = Perm4({FaceIndex[face0]:FaceIndex[flip_face[edge1, face1]],
Expand All @@ -48,7 +48,7 @@

# Another table to speed Arrow.opposite

_arrow_opposite_dict = dict()
_arrow_opposite_dict = {}
for edge, face in EdgeFacePairs:
tail = comp(face)
head = face & comp(edge)
Expand All @@ -59,7 +59,7 @@

# Another table to speed Arrow.next

_arrow_next_dict = dict()
_arrow_next_dict = {}
for edge, face in EdgeFacePairs:
for perm in Perm4.S4():
new_edge = perm.image(edge)
Expand Down
4 changes: 2 additions & 2 deletions python/snap/t3mlite/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# other_arrow = arrow.copy().opposite()
# tail, head = other_arrow.tail(), other_arrow.head()

_edge_add_corner_dict = dict()
_edge_add_corner_dict = {}
for edge, face in EdgeFacePairs:
other_arrow = Arrow(edge, face, None).opposite()
_edge_add_corner_dict[edge, face] = other_arrow.tail(), other_arrow.head()
Expand All @@ -35,7 +35,7 @@ def __init__(self):
self.Vertices = [] # pairs: (initial Vertex, terminal Vertex)
self.LeftBdryArrow = None # Arrows representing the two boundary faces,
self.RightBdryArrow = None # if this is a boundary edge.
self._edge_orient_cache = dict()
self._edge_orient_cache = {}

def __repr__(self):
if self.Index > -1:
Expand Down
8 changes: 4 additions & 4 deletions python/snap/t3mlite/test_vs_regina.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

def hash_t3m_surface(surface):
ans = [surface.EulerCharacteristic]
ans += sorted(list(surface.EdgeWeights))
ans += sorted(list(surface.Quadvector))
ans += sorted(surface.EdgeWeights)
ans += sorted(surface.Quadvector)
return ans


Expand Down Expand Up @@ -66,8 +66,8 @@ def compare_cusped(snappy_manifold):
t = R.getNumberOfTetrahedra()
regina_surfaces = list(vertex_surfaces(R))
r_hashes = sorted(
sorted(sorted(int(S.getQuadCoord(i, j).stringValue())
for i in range(t) for j in range(3)))
sorted(int(S.getQuadCoord(i, j).stringValue())
for i in range(t) for j in range(3))
for S in regina_surfaces)
r_slopes = sorted(map(regina_boundary_slope, regina_surfaces))

Expand Down
2 changes: 1 addition & 1 deletion python/snap/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_manifold(manifold):
return snap.shapes.gluing_equation_error(eqns, shapes)

def test_census(name, census):
manifolds = [M for M in census]
manifolds = list(census)
print('Checking gluing equations for %d %s manifolds' % (len(manifolds), name))
max_error = pari(0)
for i, M in enumerate(manifolds):
Expand Down
4 changes: 2 additions & 2 deletions python/tkterminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def stem(self, wordlist):
return wordlist[0]
result = ''
for n in range(1,100):
heads = set(w[:n] for w in wordlist)
heads = {w[:n] for w in wordlist}
if len(heads) > 1:
return result
elif len(heads) == 1:
Expand Down Expand Up @@ -733,7 +733,7 @@ def clean_code(self, code):
"""
if not code.strip():
return '\n'
lines = [line for line in code.split('\n')]
lines = list(code.split('\n'))
clean_lines = [lines[0].lstrip()]
for line in lines[1:]:
try:
Expand Down
Loading

0 comments on commit 40fd318

Please sign in to comment.