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

fixing some details in graphs/ (pep E275; ruff UP024, etc) #36967

Merged
merged 1 commit into from
Jan 14, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/sage/combinat/cluster_algebra_quiver/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2175,7 +2175,7 @@ def d_vector_fan(self):
...
ValueError: only makes sense for quivers of finite type
"""
if not(self.is_finite()):
if not self.is_finite():
raise ValueError('only makes sense for quivers of finite type')

from .cluster_seed import ClusterSeed
Expand Down
6 changes: 3 additions & 3 deletions src/sage/graphs/bipartite_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ def _flip_vertices(self, vertices):
self.right.remove(vertex)
self.left.add(vertex)
else:
raise RuntimeError("vertex ({0}) is neither in left nor in right".format(vertex))
raise RuntimeError(f"vertex ({vertex}) is neither in left nor in right")

def add_edge(self, u, v=None, label=None):
r"""
Expand Down Expand Up @@ -1749,7 +1749,7 @@ def load_afile(self, fname):
# open the file
try:
fi = open(fname, "r")
except IOError:
except OSError:
print("unable to open file <<" + fname + ">>")
return None

Expand Down Expand Up @@ -1849,7 +1849,7 @@ def save_afile(self, fname):
# open the file
try:
fi = open(fname, "w")
except IOError:
except OSError:
print("Unable to open file <<" + fname + ">>.")
return

Expand Down
4 changes: 2 additions & 2 deletions src/sage/graphs/digraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3000,7 +3000,7 @@ def cycle_iter(v):
try:
cycle = next(vi)
cycles.append((len(cycle), cycle))
except(StopIteration):
except StopIteration:
pass
# Since we always extract a shortest path, using a heap
# can speed up the algorithm
Expand All @@ -3015,7 +3015,7 @@ def cycle_iter(v):
try:
cycle = next(vertex_iterators[shortest_cycle[0]])
heappush(cycles, (len(cycle), cycle))
except(StopIteration):
except StopIteration:
pass

def all_simple_cycles(self, starting_vertices=None, rooted=False,
Expand Down
4 changes: 2 additions & 2 deletions src/sage/graphs/generators/smallgraphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4803,7 +4803,7 @@ def JankoKharaghaniGraph(v):
# The notations of [JK02] are rather tricky, and so this code attempts to
# stick as much as possible to the paper's variable names.

assert(v in [1800, 936])
assert v in [1800, 936]

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

# The value w_{ij} is understood in the paper as matrix generated by Omega
# acting on the left of a matrix L, which we now define.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/generic_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6276,7 +6276,7 @@ def genus(self, set_embedding=True, on_embedding=None, minimal=True, maximal=Fal
raise ValueError("on_embedding is not a valid option when circular is defined")
boundary = circular
if hasattr(G, '_embedding'):
del(G._embedding)
del G._embedding

extra = G.add_vertex()
G.add_edges((vertex, extra) for vertex in boundary)
Expand Down
10 changes: 5 additions & 5 deletions src/sage/graphs/graph_decompositions/modular_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ def test_gamma_modules(trials, vertices, prob, verbose=False):
m_list = list(module)
for v in g:
if v not in module:
assert(either_connected_or_not_connected(v, m_list, g))
assert either_connected_or_not_connected(v, m_list, g)
if verbose:
print("Passes!")

Expand Down Expand Up @@ -1275,10 +1275,10 @@ def permute_decomposition(trials, algorithm, vertices, prob, verbose=False):
print(random_perm)
t1 = algorithm(g1)
t2 = algorithm(g2)
assert(test_modular_decomposition(t1, g1))
assert(test_modular_decomposition(t2, g2))
assert test_modular_decomposition(t1, g1)
assert test_modular_decomposition(t2, g2)
t1p = relabel_tree(t1, random_perm)
assert(equivalent_trees(t1p, t2))
assert equivalent_trees(t1p, t2)
if verbose:
print("Passes!")

Expand Down Expand Up @@ -1422,6 +1422,6 @@ def recreate_decomposition(trials, algorithm, max_depth, max_fan_out,
reconstruction = algorithm(graph)
if verbose:
print_md_tree(reconstruction)
assert(equivalent_trees(rand_tree, reconstruction))
assert equivalent_trees(rand_tree, reconstruction)
if verbose:
print("Passes!")
10 changes: 5 additions & 5 deletions src/sage/graphs/graph_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1529,10 +1529,10 @@ def _read_planar_code(self, code_input):
has_loops = True
G = graph.Graph(edges_g, loops=has_loops)

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

def fullerenes(self, order, ipr=False):
r"""
Expand Down Expand Up @@ -1710,7 +1710,7 @@ def fusenes(self, hexagon_count, benzenoids=False):
g = {1: [6, 2], 2: [1, 3], 3: [2, 4], 4: [3, 5], 5: [4, 6], 6: [5, 1]}
G = graph.Graph(g)
G.set_embedding(g)
yield(G)
yield G
return

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

for G in graphs._read_planar_code(sp.stdout):
yield(G)
yield G

def plantri_gen(self, options=""):
r"""
Expand Down Expand Up @@ -2144,7 +2144,7 @@ def planar_graphs(self, order, minimum_degree=None,
if minimum_degree == 0:
G = graph.Graph(1)
G.set_embedding({0: []})
yield(G)
yield G
return

cmd = '-p{}m{}c{}{}{} {} {} {}'
Expand Down
13 changes: 6 additions & 7 deletions src/sage/graphs/graph_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,9 @@ def __eq__(self, other):
sage: opts1 == opts2
False
"""
if not(isinstance(other, GraphLatex)):
if not isinstance(other, GraphLatex):
return False
else:
return self._options == other._options
return self._options == other._options

def _repr_(self):
r"""
Expand Down Expand Up @@ -1128,9 +1127,9 @@ def set_option(self, option_name, option_value=None):
raise ValueError('%s option must be one of: tkz_graph, dot2tex not %s' % (name, value))
elif name == 'units' and value not in unit_names:
raise ValueError('%s option must be one of: in, mm, cm, pt, em, ex, not %s' % (name, value))
elif name == 'graphic_size' and not(isinstance(value, tuple) and (len(value) == 2)):
elif name == 'graphic_size' and not (isinstance(value, tuple) and (len(value) == 2)):
raise ValueError('%s option must be an ordered pair, not %s' % (name, value))
elif name == 'margins' and not((isinstance(value, tuple)) and (len(value) == 4)):
elif name == 'margins' and not ((isinstance(value, tuple)) and (len(value) == 4)):
raise ValueError('%s option must be 4-tuple, not %s' % (name, value))
elif name in color_options:
try:
Expand Down Expand Up @@ -1204,14 +1203,14 @@ def set_option(self, option_name, option_value=None):
raise TypeError('%s option must be a dictionary, not %s' % (name, value))
else:
for key, p in value.items():
if not(type(p) in [float, RealLiteral] and (0 <= p) and (p <= 1)) and not(p in label_places):
if not (type(p) in [float, RealLiteral] and (0 <= p) and (p <= 1)) and (p not in label_places):
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))
elif name == 'loop_placements':
if not isinstance(value, dict):
raise TypeError('%s option must be a dictionary, not %s' % (name, value))
else:
for key, p in value.items():
if not((isinstance(p, tuple)) and (len(p) == 2) and (p[0] >= 0) and (p[1] in compass_points)):
if not ((isinstance(p, tuple)) and (len(p) == 2) and (p[0] >= 0) and (p[1] in compass_points)):
raise ValueError('%s option for %s needs to be a positive number and a compass point (like "EA"), not %s' % (name, key, p))
# These have been verified as tuples before going into this next check
elif name in positive_tuples:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/graphs/isgci.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def _download_db(self):
try:
z.extract(_XML_FILE, GRAPHS_DATA_DIR)
z.extract(_SMALLGRAPHS_FILE, GRAPHS_DATA_DIR)
except IOError:
except OSError:
pass

def _parse_db(self, directory):
Expand Down Expand Up @@ -915,7 +915,7 @@ def _get_ISGCI(self):
else:
directory = os.path.join(GRAPHS_DATA_DIR, _XML_FILE)

except IOError:
except OSError:
directory = os.path.join(GRAPHS_DATA_DIR, _XML_FILE)

self._parse_db(directory)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/schnyder.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ def minimal_schnyder_wood(graph, root_edge=None, minimal=True, check=True):
raise ValueError('not a planar graph')
if not all(len(u) == 3 for u in graph.faces()):
raise ValueError('not a triangulation')
if not(a in graph.neighbors(b)):
if a not in graph.neighbors(b):
raise ValueError('not a valid root edge')

new_g = DiGraph()
Expand Down