Skip to content

Commit 21458ae

Browse files
committed
fixing some details in graphs/ (pep E275; ruff UP024, etc)
1 parent e249bef commit 21458ae

File tree

10 files changed

+28
-29
lines changed

10 files changed

+28
-29
lines changed

src/sage/combinat/cluster_algebra_quiver/quiver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,7 @@ def d_vector_fan(self):
21752175
...
21762176
ValueError: only makes sense for quivers of finite type
21772177
"""
2178-
if not(self.is_finite()):
2178+
if not self.is_finite():
21792179
raise ValueError('only makes sense for quivers of finite type')
21802180

21812181
from .cluster_seed import ClusterSeed

src/sage/graphs/bipartite_graph.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ def _flip_vertices(self, vertices):
979979
self.right.remove(vertex)
980980
self.left.add(vertex)
981981
else:
982-
raise RuntimeError("vertex ({0}) is neither in left nor in right".format(vertex))
982+
raise RuntimeError(f"vertex ({vertex}) is neither in left nor in right")
983983

984984
def add_edge(self, u, v=None, label=None):
985985
r"""
@@ -1749,7 +1749,7 @@ def load_afile(self, fname):
17491749
# open the file
17501750
try:
17511751
fi = open(fname, "r")
1752-
except IOError:
1752+
except OSError:
17531753
print("unable to open file <<" + fname + ">>")
17541754
return None
17551755

@@ -1849,7 +1849,7 @@ def save_afile(self, fname):
18491849
# open the file
18501850
try:
18511851
fi = open(fname, "w")
1852-
except IOError:
1852+
except OSError:
18531853
print("Unable to open file <<" + fname + ">>.")
18541854
return
18551855

src/sage/graphs/digraph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,7 +3000,7 @@ def cycle_iter(v):
30003000
try:
30013001
cycle = next(vi)
30023002
cycles.append((len(cycle), cycle))
3003-
except(StopIteration):
3003+
except StopIteration:
30043004
pass
30053005
# Since we always extract a shortest path, using a heap
30063006
# can speed up the algorithm
@@ -3015,7 +3015,7 @@ def cycle_iter(v):
30153015
try:
30163016
cycle = next(vertex_iterators[shortest_cycle[0]])
30173017
heappush(cycles, (len(cycle), cycle))
3018-
except(StopIteration):
3018+
except StopIteration:
30193019
pass
30203020

30213021
def all_simple_cycles(self, starting_vertices=None, rooted=False,

src/sage/graphs/generators/smallgraphs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4803,7 +4803,7 @@ def JankoKharaghaniGraph(v):
48034803
# The notations of [JK02] are rather tricky, and so this code attempts to
48044804
# stick as much as possible to the paper's variable names.
48054805

4806-
assert(v in [1800, 936])
4806+
assert v in [1800, 936]
48074807

48084808
J = matrix.ones
48094809
I = matrix.identity
@@ -4842,7 +4842,7 @@ def JankoKharaghaniGraph(v):
48424842
U = matrix.circulant([int(i == 1) for i in range(2 * n)])
48434843
N = matrix.diagonal([1 if i else -1 for i in range(2 * n)])
48444844
Omega = (U * N)**6
4845-
assert(Omega**12 == I(36))
4845+
assert Omega**12 == I(36)
48464846

48474847
# The value w_{ij} is understood in the paper as matrix generated by Omega
48484848
# acting on the left of a matrix L, which we now define.

src/sage/graphs/generic_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6276,7 +6276,7 @@ def genus(self, set_embedding=True, on_embedding=None, minimal=True, maximal=Fal
62766276
raise ValueError("on_embedding is not a valid option when circular is defined")
62776277
boundary = circular
62786278
if hasattr(G, '_embedding'):
6279-
del(G._embedding)
6279+
del G._embedding
62806280

62816281
extra = G.add_vertex()
62826282
G.add_edges((vertex, extra) for vertex in boundary)

src/sage/graphs/graph_decompositions/modular_decomposition.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ def test_gamma_modules(trials, vertices, prob, verbose=False):
12451245
m_list = list(module)
12461246
for v in g:
12471247
if v not in module:
1248-
assert(either_connected_or_not_connected(v, m_list, g))
1248+
assert either_connected_or_not_connected(v, m_list, g)
12491249
if verbose:
12501250
print("Passes!")
12511251

@@ -1275,10 +1275,10 @@ def permute_decomposition(trials, algorithm, vertices, prob, verbose=False):
12751275
print(random_perm)
12761276
t1 = algorithm(g1)
12771277
t2 = algorithm(g2)
1278-
assert(test_modular_decomposition(t1, g1))
1279-
assert(test_modular_decomposition(t2, g2))
1278+
assert test_modular_decomposition(t1, g1)
1279+
assert test_modular_decomposition(t2, g2)
12801280
t1p = relabel_tree(t1, random_perm)
1281-
assert(equivalent_trees(t1p, t2))
1281+
assert equivalent_trees(t1p, t2)
12821282
if verbose:
12831283
print("Passes!")
12841284

@@ -1422,6 +1422,6 @@ def recreate_decomposition(trials, algorithm, max_depth, max_fan_out,
14221422
reconstruction = algorithm(graph)
14231423
if verbose:
14241424
print_md_tree(reconstruction)
1425-
assert(equivalent_trees(rand_tree, reconstruction))
1425+
assert equivalent_trees(rand_tree, reconstruction)
14261426
if verbose:
14271427
print("Passes!")

src/sage/graphs/graph_generators.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,10 +1529,10 @@ def _read_planar_code(self, code_input):
15291529
has_loops = True
15301530
G = graph.Graph(edges_g, loops=has_loops)
15311531

1532-
if not(G.has_multiple_edges() or has_loops):
1532+
if not (G.has_multiple_edges() or has_loops):
15331533
embed_g = {i + 1: di for i, di in enumerate(g)}
15341534
G.set_embedding(embed_g)
1535-
yield(G)
1535+
yield G
15361536

15371537
def fullerenes(self, order, ipr=False):
15381538
r"""
@@ -1710,7 +1710,7 @@ def fusenes(self, hexagon_count, benzenoids=False):
17101710
g = {1: [6, 2], 2: [1, 3], 3: [2, 4], 4: [3, 5], 5: [4, 6], 6: [5, 1]}
17111711
G = graph.Graph(g)
17121712
G.set_embedding(g)
1713-
yield(G)
1713+
yield G
17141714
return
17151715

17161716
from sage.features.graph_generators import Benzene
@@ -1728,7 +1728,7 @@ def fusenes(self, hexagon_count, benzenoids=False):
17281728
sp.stdout.reconfigure(newline='')
17291729

17301730
for G in graphs._read_planar_code(sp.stdout):
1731-
yield(G)
1731+
yield G
17321732

17331733
def plantri_gen(self, options=""):
17341734
r"""
@@ -2144,7 +2144,7 @@ def planar_graphs(self, order, minimum_degree=None,
21442144
if minimum_degree == 0:
21452145
G = graph.Graph(1)
21462146
G.set_embedding({0: []})
2147-
yield(G)
2147+
yield G
21482148
return
21492149

21502150
cmd = '-p{}m{}c{}{}{} {} {} {}'

src/sage/graphs/graph_latex.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,9 @@ def __eq__(self, other):
589589
sage: opts1 == opts2
590590
False
591591
"""
592-
if not(isinstance(other, GraphLatex)):
592+
if not isinstance(other, GraphLatex):
593593
return False
594-
else:
595-
return self._options == other._options
594+
return self._options == other._options
596595

597596
def _repr_(self):
598597
r"""
@@ -1128,9 +1127,9 @@ def set_option(self, option_name, option_value=None):
11281127
raise ValueError('%s option must be one of: tkz_graph, dot2tex not %s' % (name, value))
11291128
elif name == 'units' and value not in unit_names:
11301129
raise ValueError('%s option must be one of: in, mm, cm, pt, em, ex, not %s' % (name, value))
1131-
elif name == 'graphic_size' and not(isinstance(value, tuple) and (len(value) == 2)):
1130+
elif name == 'graphic_size' and not (isinstance(value, tuple) and (len(value) == 2)):
11321131
raise ValueError('%s option must be an ordered pair, not %s' % (name, value))
1133-
elif name == 'margins' and not((isinstance(value, tuple)) and (len(value) == 4)):
1132+
elif name == 'margins' and not ((isinstance(value, tuple)) and (len(value) == 4)):
11341133
raise ValueError('%s option must be 4-tuple, not %s' % (name, value))
11351134
elif name in color_options:
11361135
try:
@@ -1204,14 +1203,14 @@ def set_option(self, option_name, option_value=None):
12041203
raise TypeError('%s option must be a dictionary, not %s' % (name, value))
12051204
else:
12061205
for key, p in value.items():
1207-
if not(type(p) in [float, RealLiteral] and (0 <= p) and (p <= 1)) and not(p in label_places):
1206+
if not (type(p) in [float, RealLiteral] and (0 <= p) and (p <= 1)) and (p not in label_places):
12081207
raise ValueError('%s option for %s needs to be a number between 0.0 and 1.0 or a place (like "above"), not %s' % (name, key, p))
12091208
elif name == 'loop_placements':
12101209
if not isinstance(value, dict):
12111210
raise TypeError('%s option must be a dictionary, not %s' % (name, value))
12121211
else:
12131212
for key, p in value.items():
1214-
if not((isinstance(p, tuple)) and (len(p) == 2) and (p[0] >= 0) and (p[1] in compass_points)):
1213+
if not ((isinstance(p, tuple)) and (len(p) == 2) and (p[0] >= 0) and (p[1] in compass_points)):
12151214
raise ValueError('%s option for %s needs to be a positive number and a compass point (like "EA"), not %s' % (name, key, p))
12161215
# These have been verified as tuples before going into this next check
12171216
elif name in positive_tuples:

src/sage/graphs/isgci.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ def _download_db(self):
806806
try:
807807
z.extract(_XML_FILE, GRAPHS_DATA_DIR)
808808
z.extract(_SMALLGRAPHS_FILE, GRAPHS_DATA_DIR)
809-
except IOError:
809+
except OSError:
810810
pass
811811

812812
def _parse_db(self, directory):
@@ -915,7 +915,7 @@ def _get_ISGCI(self):
915915
else:
916916
directory = os.path.join(GRAPHS_DATA_DIR, _XML_FILE)
917917

918-
except IOError:
918+
except OSError:
919919
directory = os.path.join(GRAPHS_DATA_DIR, _XML_FILE)
920920

921921
self._parse_db(directory)

src/sage/graphs/schnyder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ def minimal_schnyder_wood(graph, root_edge=None, minimal=True, check=True):
804804
raise ValueError('not a planar graph')
805805
if not all(len(u) == 3 for u in graph.faces()):
806806
raise ValueError('not a triangulation')
807-
if not(a in graph.neighbors(b)):
807+
if a not in graph.neighbors(b):
808808
raise ValueError('not a valid root edge')
809809

810810
new_g = DiGraph()

0 commit comments

Comments
 (0)