Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some fixes by ruff about comprehensions, etc #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dev/DTcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def upper_pair(self):
return (0,2) if bool(first % 2) ^ even_over else (1,3)


class DTPath():
class DTPath:
"""
An iterator which starts at a FatEdge and walks around the
link component containing that edge. A DTPath raises
Expand Down Expand Up @@ -215,7 +215,7 @@ def clear(self):
"""
for e in self.edges:
e.marked = False
self.marked_valences = dict( (v,0) for v in self.vertices )
self.marked_valences = { v: 0 for v in self.vertices }

def push(self, flips):
"""
Expand Down Expand Up @@ -283,7 +283,7 @@ def marked_arc(self, vertex):
left_path, right_path, vertices = [], [], set()
vertices.add(vertex)
try:
left, right = [e for e in self(vertex) if e.marked]
left, right = (e for e in self(vertex) if e.marked)
except ValueError:
raise RuntimeError('Vertex must have two marked edges.')
for edge, path in (left, left_path), (right, right_path):
Expand Down Expand Up @@ -533,7 +533,7 @@ def KLP_dict(self, vertex, indices):
# This assumes that the diagram has no loops, and that each component
# meets the next one (so in particular the diagram is connected.

class DTcodec():
class DTcodec:
"""
Codec for DT codes of a link projection.
"""
Expand Down Expand Up @@ -871,7 +871,7 @@ def KLPProjection(self):
vertices = list(G.vertices)
num_crossings = len(vertices)
num_components = len(self.code)
KLP_indices = dict( (v,n) for n, v in enumerate(vertices))
KLP_indices = { v: n for n, v in enumerate(vertices)}
KLP_crossings = [G.KLP_dict(v, KLP_indices) for v in vertices]
return len(G.vertices), 0, len(self.code), KLP_crossings

Expand Down
4 changes: 2 additions & 2 deletions dev/dev_jennet/bridge_finding.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def find_bridges(G):
bridges = []

verts = G.vertices()
low = dict([(v,-1) for v in verts])
preorder = dict([(v,-1) for v in verts])
low = {v: -1 for v in verts}
preorder = {v: -1 for v in verts}

for v in verts:
if preorder[v] == -1:
Expand Down
6 changes: 3 additions & 3 deletions dev/dev_malik/fast_jones_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def simplify_monomial(monomial):
# monomial = remove_squares(monomial)
# monomial = remove_loops(monomial)

strand_vars = monomial.free_symbols - set([A])
strand_vars = monomial.free_symbols - {A}
strand_labels = all_labels(strand_vars)

return monomial
Expand All @@ -129,15 +129,15 @@ def combine_strands(v1, v2, common_label):

def remove_squares(monomial):
A, B = sympy.symbols('A,B')
strand_vars = monomial.free_symbols - set([A,B])
strand_vars = monomial.free_symbols - {A,B}
for v in strand_vars:
monomial = monomial.subs(v*v,-A**2-(1/A)**2)
return monomial


def remove_loops(monomial):
A, B = sympy.symbols('A,B')
strand_vars = monomial.free_symbols - set([A,B])
strand_vars = monomial.free_symbols - {A,B}
for v in strand_vars:
l1, l2 = var_to_strand_labels(v)
if l1 == l2:
Expand Down
6 changes: 3 additions & 3 deletions dev/dev_malik/mutation/tangle_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def all_cross_strands(self):
other_ends_seen.append(end)
orientations, over_or_under = crossing_orientations(strands)
cs_seen = [cs for strand in strands for cs in strand]
seen_once = set(cs[0] for cs in cs_seen)
seen_once = {cs[0] for cs in cs_seen}
for crossing in orientations:
seen_once.remove(crossing)
for strand in strands:
Expand Down Expand Up @@ -873,7 +873,7 @@ def tangle_cut(link, cycle):
def fill_in_crossings(link,sides):
crossing_sides = {x[0]:sides[x] for x in sides}
crossing_labels = map(lambda c: c.label,link.crossings)
crossings_to_sort = set(crossing_labels)-set(x[0] for x in sides)
crossings_to_sort = set(crossing_labels)-{x[0] for x in sides}
while len(crossings_to_sort) > 0:
start_crossing = crossings_to_sort.pop()
accumulated_crossings = [start_crossing]
Expand Down Expand Up @@ -1158,7 +1158,7 @@ def close_float_sets(L1, L2, tolerance):
print(v,avg_vol)
"""

a, b, c, d, e, f, g, h = [spherogram.Crossing(x) for x in 'abcdefgh']
a, b, c, d, e, f, g, h = (spherogram.Crossing(x) for x in 'abcdefgh')
a[0] = e[2]
a[1] = b[3]
a[3] = e[3]
Expand Down
4 changes: 2 additions & 2 deletions dev/dev_malik/thompson/graphknotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ def edge_to_str_pair(edge):


def doubled_edge_to_str_pair(e):
s1 = set([e[0].split()[0].split('\'')[1], e[0].split()[1].split('\'')[1]])
s2 = set([e[1].split()[0].split('\'')[1], e[1].split()[1].split('\'')[1]])
s1 = {e[0].split()[0].split('\'')[1], e[0].split()[1].split('\'')[1]}
s2 = {e[1].split()[0].split('\'')[1], e[1].split()[1].split('\'')[1]}
return [s1,s2]

def simple_cut(link, cs1, cs2):
Expand Down
2 changes: 1 addition & 1 deletion dev/dev_malik/unknotting_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def doubly_connected_crossing(link):
doubly_connected = None
for c in link.crossings:
num_neighbors = len(set(x[0] for x in c.adjacent))
num_neighbors = len({x[0] for x in c.adjacent})
if num_neighbors == 2:
return c
elif num_neighbors == 3:
Expand Down
2 changes: 1 addition & 1 deletion dev/dt_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def fill_vols(M):

def plink_component_order_test(N):
M2 = snappy.Manifold()
return set(test_DT(dt, M2) for dt in asymmetric_link_DTs(N))
return {test_DT(dt, M2) for dt in asymmetric_link_DTs(N)}
10 changes: 5 additions & 5 deletions dev/dt_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def test1():
def test2():
keys = G.incidence_dict.keys()
v = keys[0]
D = dict( (k, (i, range(10*i, 10*(i+10)))) for i, k in enumerate(keys))
D = { k: (i, range(10*i, 10*(i+10))) for i, k in enumerate(keys)}
for i in range(155000):
D[v]


def test3():
keys = G.incidence_dict.keys()
v = keys[0]
D = dict((k, None) for i, k in enumerate(keys))
D = {k: None for i, k in enumerate(keys)}
for i in range(155000):
D[v]

Expand All @@ -58,19 +58,19 @@ def test4():
return v


class TestObject():
class TestObject:
pass


def test5():
D = dict([(TestObject(), i) for i in range(10)])
D = {TestObject(): i for i in range(10)}
k = D.keys()[0]
for i in range(10000000):
D[k]


def test6():
D = dict([(i, TestObject()) for i in range(10)])
D = {i: TestObject() for i in range(10)}
k = D.keys()[0]
for i in range(10000000):
D[k]
Expand Down
6 changes: 3 additions & 3 deletions dev/old/fastalex/exhaust.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def entry_pts_ab(crossing):
return [CrossingEntryPoint(crossing, v) for v in verts]


class StrandIndices():
class StrandIndices:
"""
A map from the crossings strands of a link L onto range(n).
"""
Expand Down Expand Up @@ -111,7 +111,7 @@ def eval_merges(merges):
assert eval_merges(m1) == eval_merges(m2)


class DrorDatum():
class DrorDatum:
"""
The (omega, A) pair which is the invariant defined in the first column of
http://www.math.toronto.edu/drorbn/Talks/Aarhus-1507/
Expand Down Expand Up @@ -192,7 +192,7 @@ def num_overlap(crossing, frontier):
return len(neighbor_strands.intersection(frontier))


class Exhaustion():
class Exhaustion:
"""
An exhaustion of a link where crossings are added in one-by-one
so that the resulting tangle is connected at every stage.
Expand Down
6 changes: 3 additions & 3 deletions dev/old/seifert_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def seifert_tree(link):
circles.
"""
circles = seifert_circles(link)
edges = [[set([n]),set([n])] for n in range(len(circles))]
edges = [[{n},{n}] for n in range(len(circles))]
for c in link.crossings:
under, over = c.entry_points()
under_circle, over_circle = -1,-1
Expand Down Expand Up @@ -92,10 +92,10 @@ def remove_admissible_move(link):
found_move = False
for e1, e2 in combinations(tree,2):
if e1[0] == e2[0]: #edges start at same point
circles = set([tree.index(e1), tree.index(e2)])
circles = {tree.index(e1), tree.index(e2)}
found_move = True
elif e1[1] == e2[1]: #edges end at same point
circles = set([tree.index(e1), tree.index(e2)])
circles = {tree.index(e1), tree.index(e2)}
found_move = True
if found_move:
move_possible = False
Expand Down
10 changes: 5 additions & 5 deletions dev/orthogonal/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __new__(self, crossing_strand, link):
return ans


class UpwardLinkDiagram():
class UpwardLinkDiagram:
def __init__(self, link):
self.link = link = link.copy()
bridge, values = bridge_LP(link)
Expand Down Expand Up @@ -185,7 +185,7 @@ def strands_below(self, crossing):
a = CrossingStrand(crossing, 0)
b = a.rotate()
while True:
if set([kinds[a], kinds[b]]).issubset(set(['up', 'min'])):
if {kinds[a], kinds[b]}.issubset({'up', 'min'}):
return a, b
a, b = b, b.rotate()

Expand Down Expand Up @@ -284,19 +284,19 @@ def bottom_pairing(snake):
cs = snake[0]
return tuple(sorted([to_index(cs), to_index(cs.opposite())]))

bottom = set(bottom_pairing(snake) for snake in self.snakes)
bottom = {bottom_pairing(snake) for snake in self.snakes}

def top_pairing(snake):
cs = snake[-1]
cn = self.adjacent_upwards(snake.final)
return tuple(sorted([to_index(cs), to_index(cn)]))

top = set(top_pairing(snake) for snake in self.snakes)
top = {top_pairing(snake) for snake in self.snakes}

return BridgeDiagram(bottom, [cd[1] for cd in cross_data], top)


class BridgeDiagram():
class BridgeDiagram:
def __init__(self, bottom, crossings, top):
self.bottom, self.crossings, self.top = bottom, crossings, top
self.width = 2 * len(bottom)
Expand Down
2 changes: 1 addition & 1 deletion dev/orthogonal/ogdf/ortho.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def link_to_gml_file(L, filename='graphs/link.gml'):
edges = collections.Counter(tuple(sorted([verts_to_int[e.tail],
verts_to_int[e.head]]))
for e in L.edges)
assert set(edges.values()).issubset(set([1, 2]))
assert set(edges.values()).issubset({1, 2})
for (a, b), m in edges.items():
if m == 2:
c = len(verts)
Expand Down
14 changes: 7 additions & 7 deletions dev/orthogonal/orthogonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,15 @@ def DAG_from_direction(self, kind):
def chain_coordinates(self, kind):
D = self.DAG_from_direction(kind)
chain_coors = topological_numbering(D)
return dict( (v,chain_coors[D.vertex_to_chain[v]]) for v in self.vertices )
return { v: chain_coors[D.vertex_to_chain[v]] for v in self.vertices }

def basic_grid_embedding(self, rotate=False):
"""
Returns the positions of vertices under the grid embedding.
"""
V = self.chain_coordinates('horizontal')
H = self.chain_coordinates('vertical')
return dict( (v,(H[v], V[v])) for v in self.vertices)
return { v: (H[v], V[v]) for v in self.vertices}

def show(self, unit=10, labels=True):
pos = self.basic_grid_embedding()
Expand Down Expand Up @@ -457,8 +457,8 @@ def __init__(self, link):
self.bend()
self.orient_edges()
self.edges = sum([F for F in self], [])
strands = set(e.crossing for e in self.edges
if isinstance(e.crossing, Strand))
strands = {e.crossing for e in self.edges
if isinstance(e.crossing, Strand)}
self.strand_CEPs = [CrossingEntryPoint(s, 0) for s in strands]
for i, c in enumerate(link.crossings):
c.label = i
Expand Down Expand Up @@ -504,7 +504,7 @@ def bend(self):
flow = networkx.min_cost_flow(N)
for a, flows in flow.iteritems():
for b, w_a in flows.iteritems():
if w_a and set(['s', 't']).isdisjoint(set([a, b])):
if w_a and {'s', 't'}.isdisjoint({a, b}):
w_b = flow[b][a]
A, B = self[a], self[b]
e_a, e_b = A.edge_of_intersection(B)
Expand Down Expand Up @@ -596,7 +596,7 @@ def plink_data(self, spacing=None, canvas_width=None):
b, a = emb[v.crossing]
vertex_positions.append( (spacing*(a+1), spacing*(b+1)) )

vert_indices = dict( (v,i) for i, v in enumerate(self.strand_CEPs))
vert_indices = { v: i for i, v in enumerate(self.strand_CEPs)}
arrows, crossings = self.break_into_arrows()
arrows = [ (vert_indices[a[0]], vert_indices[a[-1]]) for a in arrows]

Expand Down Expand Up @@ -668,7 +668,7 @@ def random_link():
def check_faces(link):
faces = link.faces()
assert len(link.vertices) - len(link.edges) + len(faces) == 2
assert set(Counter(sum( faces, [] )).values()) == set([1])
assert set(Counter(sum( faces, [] )).values()) == {1}
assert link.is_planar()


Expand Down
6 changes: 3 additions & 3 deletions dev/tangle_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def tangle_neighborhood(link,crossing,radius,return_gluings=True,hull=False):
if hull:
comps = list(boundary_components(link,crossing,radius))
largest_comp = max(comps)
sides = dict([(cslabel(cross_strand), cross_strand) for cross_strand in adjacent])
sides = {cslabel(cross_strand): cross_strand for cross_strand in adjacent}
c = largest_comp.pop()
cs = choice(c.crossing_strands())
exit_strand = meander(cs,sides)[1]
Expand Down Expand Up @@ -547,9 +547,9 @@ def fill_in_crossings(link, sides):
Returns a dictionary with the side (0 or 1) of each crossing.
"""

crossing_sides = dict([(x[0], sides[x]) for x in sides])
crossing_sides = {x[0]: sides[x] for x in sides}
crossing_labels = map(lambda c: c.label,link.crossings)
crossings_to_sort = set(crossing_labels)-set(x[0] for x in sides)
crossings_to_sort = set(crossing_labels)-{x[0] for x in sides}
while crossings_to_sort:
start_crossing = crossings_to_sort.pop()
accumulated_crossings = [start_crossing]
Expand Down
6 changes: 3 additions & 3 deletions spherogram_src/codecs/DT.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def upper_pair(self):
return (0, 2) if bool(first % 2) ^ even_over else (1, 3)


class DTPath():
class DTPath:
"""
An iterator which starts at a FatEdge and walks around the
link component containing that edge. A DTPath raises
Expand Down Expand Up @@ -278,7 +278,7 @@ def marked_arc(self, vertex):
left_path, right_path, vertices = [], [], set()
vertices.add(vertex)
try:
left, right = [e for e in self(vertex) if e.marked]
left, right = (e for e in self(vertex) if e.marked)
except ValueError:
raise RuntimeError('Vertex must have two marked edges.')
for edge, path in (left, left_path), (right, right_path):
Expand Down Expand Up @@ -533,7 +533,7 @@ def KLP_dict(self, vertex, indices):
# meets the next one (so in particular the diagram is connected.


class DTcodec():
class DTcodec:
"""
Codec for DT codes of a link projection.
"""
Expand Down
Loading
Loading