From d0b7baec79231951deb931e1352aedc7c29a2692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 16 Dec 2023 21:45:57 +0100 Subject: [PATCH] some ruff fixes and error links in the graphs folder --- src/sage/graphs/base/c_graph.pyx | 6 +++--- src/sage/graphs/base/graph_backends.pyx | 2 +- src/sage/graphs/bipartite_graph.py | 1 - src/sage/graphs/bliss.pyx | 7 ++++--- src/sage/graphs/digraph.py | 10 +++++----- src/sage/graphs/digraph_generators.py | 2 +- src/sage/graphs/domination.py | 1 - src/sage/graphs/generators/basic.py | 3 +-- src/sage/graphs/generators/chessboard.py | 1 - src/sage/graphs/generators/degree_sequence.py | 5 ++--- src/sage/graphs/generators/families.py | 7 +++---- src/sage/graphs/generators/intersection.py | 1 - src/sage/graphs/generators/platonic_solids.py | 1 - src/sage/graphs/generators/random.py | 1 - src/sage/graphs/generators/smallgraphs.py | 1 - src/sage/graphs/generators/world_map.py | 1 - src/sage/graphs/generic_graph.py | 17 ++++++++--------- src/sage/graphs/graph.py | 5 ++--- .../modular_decomposition.py | 1 - src/sage/graphs/graph_generators.py | 2 +- src/sage/graphs/graph_input.py | 2 +- src/sage/graphs/graph_latex.py | 2 +- src/sage/graphs/hypergraph_generators.py | 2 +- src/sage/graphs/lovasz_theta.py | 1 - src/sage/graphs/pq_trees.py | 4 ++-- src/sage/graphs/schnyder.py | 2 +- src/sage/graphs/tutte_polynomial.py | 4 ++-- 27 files changed, 39 insertions(+), 53 deletions(-) diff --git a/src/sage/graphs/base/c_graph.pyx b/src/sage/graphs/base/c_graph.pyx index 7ca6c5dd124..70ce392a43c 100644 --- a/src/sage/graphs/base/c_graph.pyx +++ b/src/sage/graphs/base/c_graph.pyx @@ -624,8 +624,8 @@ cdef class CGraph: OUTPUT: - - Raise a ``NotImplementedError``. This method is not implemented in - this base class. A child class should provide a suitable + - Raise a :class:`NotImplementedError`. This method is not implemented + in this base class. A child class should provide a suitable implementation. .. SEEALSO:: @@ -1267,7 +1267,7 @@ cdef class CGraph: OUTPUT: - - Raise ``NotImplementedError``. This method is not implemented at + - Raise :class:`NotImplementedError`. This method is not implemented at the :class:`CGraph` level. A child class should provide a suitable implementation. diff --git a/src/sage/graphs/base/graph_backends.pyx b/src/sage/graphs/base/graph_backends.pyx index 863f61be013..77961c33cf6 100644 --- a/src/sage/graphs/base/graph_backends.pyx +++ b/src/sage/graphs/base/graph_backends.pyx @@ -6,7 +6,7 @@ This module implements :class:`GenericGraphBackend` (the base class for backends). Any graph backend must redefine the following methods (for which -:class:`GenericGraphBackend` raises a ``NotImplementedError``) +:class:`GenericGraphBackend` raises a :class:`NotImplementedError`) .. csv-table:: :class: contentstable diff --git a/src/sage/graphs/bipartite_graph.py b/src/sage/graphs/bipartite_graph.py index 0a03affa422..6bb65e6ad33 100644 --- a/src/sage/graphs/bipartite_graph.py +++ b/src/sage/graphs/bipartite_graph.py @@ -1,5 +1,4 @@ # autopep8: off -# -*- coding: utf-8 -*- r""" Bipartite graphs diff --git a/src/sage/graphs/bliss.pyx b/src/sage/graphs/bliss.pyx index eac56e21f0d..c623b5fe402 100644 --- a/src/sage/graphs/bliss.pyx +++ b/src/sage/graphs/bliss.pyx @@ -396,9 +396,10 @@ cpdef canonical_form(G, partition=None, return_graph=False, use_edge_labels=True canonical graph of ``G`` or its set of edges - ``use_edge_labels`` -- boolean (default: ``True``); whether to consider - edge labels. The edge labels are assumed to be hashable and sortable. If - this is not the case (ie a ``TypeError`` is raised), the algorithm will - consider the string representations of the labels instead of the labels. + edge labels. The edge labels are assumed to be hashable and + sortable. If this is not the case (ie a :class:`TypeError` is + raised), the algorithm will consider the string representations + of the labels instead of the labels. - ``certificate`` -- boolean (default: ``False``); when set to ``True``, returns the labeling of G into a canonical graph diff --git a/src/sage/graphs/digraph.py b/src/sage/graphs/digraph.py index 8ba57d90b3c..a5d43d48085 100644 --- a/src/sage/graphs/digraph.py +++ b/src/sage/graphs/digraph.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Directed graphs @@ -3187,9 +3186,9 @@ def topological_sort(self, implementation="default"): """ Return a topological sort of the digraph if it is acyclic. - If the digraph contains a directed cycle, a ``TypeError`` is raised. As - topological sorts are not necessarily unique, different implementations - may yield different results. + If the digraph contains a directed cycle, a :class:`TypeError` + is raised. As topological sorts are not necessarily unique, + different implementations may yield different results. A topological sort is an ordering of the vertices of the digraph such that each vertex comes before all of its successors. That is, if `u` @@ -3269,7 +3268,8 @@ def topological_sort_generator(self): Return an iterator over all topological sorts of the digraph if it is acyclic. - If the digraph contains a directed cycle, a ``TypeError`` is raised. + If the digraph contains a directed cycle, a :class:`TypeError` + is raised. A topological sort is an ordering of the vertices of the digraph such that each vertex comes before all of its successors. That is, if u comes diff --git a/src/sage/graphs/digraph_generators.py b/src/sage/graphs/digraph_generators.py index 2b29e0e73ef..d182f49afb1 100644 --- a/src/sage/graphs/digraph_generators.py +++ b/src/sage/graphs/digraph_generators.py @@ -74,7 +74,7 @@ from sage.graphs.graph import Graph -class DiGraphGenerators(): +class DiGraphGenerators: r""" A class consisting of constructors for several common digraphs, including orderly generation of isomorphism class representatives. diff --git a/src/sage/graphs/domination.py b/src/sage/graphs/domination.py index 7f631fcfe28..6323cdd29e4 100644 --- a/src/sage/graphs/domination.py +++ b/src/sage/graphs/domination.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Domination diff --git a/src/sage/graphs/generators/basic.py b/src/sage/graphs/generators/basic.py index 5dbacb4de26..0dc2c00baef 100644 --- a/src/sage/graphs/generators/basic.py +++ b/src/sage/graphs/generators/basic.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Basic graphs @@ -400,7 +399,7 @@ def CompleteGraph(n): G.set_pos({0: (0, 0)}) else: G._circle_embedding(list(range(n)), angle=pi/2) - G.add_edges(((i, j) for i in range(n) for j in range(i + 1, n))) + G.add_edges((i, j) for i in range(n) for j in range(i + 1, n)) return G def CorrelationGraph(seqs, alpha, include_anticorrelation): diff --git a/src/sage/graphs/generators/chessboard.py b/src/sage/graphs/generators/chessboard.py index dfe5b15b273..a76d6f98de7 100644 --- a/src/sage/graphs/generators/chessboard.py +++ b/src/sage/graphs/generators/chessboard.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Chessboard graphs diff --git a/src/sage/graphs/generators/degree_sequence.py b/src/sage/graphs/generators/degree_sequence.py index f5e68d89c79..05c021403b0 100644 --- a/src/sage/graphs/generators/degree_sequence.py +++ b/src/sage/graphs/generators/degree_sequence.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Graphs with a given degree sequence @@ -98,8 +97,8 @@ def DegreeSequenceBipartite(s1, s2): True Some sequences being incompatible if, for example, their sums are different, - the functions raises a ``ValueError`` when no graph corresponding to the - degree sequences exists:: + the functions raises a :class:`ValueError` when no graph corresponding + to the degree sequences exists:: sage: g = graphs.DegreeSequenceBipartite([2,2,2,2,1],[5,5]) # needs sage.combinat sage.modules Traceback (most recent call last): diff --git a/src/sage/graphs/generators/families.py b/src/sage/graphs/generators/families.py index 85ea52a4571..452a3cd73ab 100644 --- a/src/sage/graphs/generators/families.py +++ b/src/sage/graphs/generators/families.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Various families of graphs @@ -594,7 +593,7 @@ def BarbellGraph(n1, n2): OUTPUT: - A barbell graph of order ``2*n1 + n2``. A ``ValueError`` is + A barbell graph of order ``2*n1 + n2``. A :class:`ValueError` is returned if ``n1 < 2`` or ``n2 < 0``. PLOTTING: @@ -929,7 +928,7 @@ def BubbleSortGraph(n): OUTPUT: The bubble sort graph `B(n)` on `n` symbols. If `n < 1`, a - ``ValueError`` is returned. + :class:`ValueError` is returned. EXAMPLES:: @@ -2714,7 +2713,7 @@ def SwitchedSquaredSkewHadamardMatrixGraph(n): G = SquaredSkewHadamardMatrixGraph(n).complement() G.add_vertex((4 * n - 1)**2) G.seidel_switching(list(range((4 * n - 1) * (2 * n - 1)))) - G.name("switch skewhad^2+*_" + str((n))) + G.name("switch skewhad^2+*_" + str(n)) return G diff --git a/src/sage/graphs/generators/intersection.py b/src/sage/graphs/generators/intersection.py index 0d19d30f9ea..0434806fb73 100644 --- a/src/sage/graphs/generators/intersection.py +++ b/src/sage/graphs/generators/intersection.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Intersection graphs diff --git a/src/sage/graphs/generators/platonic_solids.py b/src/sage/graphs/generators/platonic_solids.py index d3bc60a9974..5a572611539 100644 --- a/src/sage/graphs/generators/platonic_solids.py +++ b/src/sage/graphs/generators/platonic_solids.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" 1-skeletons of Platonic solids diff --git a/src/sage/graphs/generators/random.py b/src/sage/graphs/generators/random.py index 22c1f583f6a..e0868b36e21 100644 --- a/src/sage/graphs/generators/random.py +++ b/src/sage/graphs/generators/random.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Random graphs diff --git a/src/sage/graphs/generators/smallgraphs.py b/src/sage/graphs/generators/smallgraphs.py index 3b47f29f2ff..bde0cafc0a8 100644 --- a/src/sage/graphs/generators/smallgraphs.py +++ b/src/sage/graphs/generators/smallgraphs.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Various small graphs diff --git a/src/sage/graphs/generators/world_map.py b/src/sage/graphs/generators/world_map.py index f131aa446e2..76ec2b4f9ae 100644 --- a/src/sage/graphs/generators/world_map.py +++ b/src/sage/graphs/generators/world_map.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Graphs from the World Map diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 0f0f995bfbd..ca365540ffb 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Generic graphs (common to directed/undirected) @@ -2933,8 +2932,8 @@ def _check_embedding_validity(self, embedding=None, boolean=True): ``_embedding`` - ``boolean`` -- boolean (default: ``True``); -- whether to return a - boolean answer or raise a ``ValueError`` exception if the embedding is - invalid + boolean answer or raise a :class:`ValueError` exception + if the embedding is invalid EXAMPLES:: @@ -3443,8 +3442,8 @@ def allow_multiple_edges(self, new, check=True, keep_label='any'): .. WARNING:: ``'min'`` and ``'max'`` only works if the labels can be compared. A - ``TypeError`` might be raised when working with non-comparable - objects in Python 3. + :class:`TypeError` might be raised when working with non-comparable + objects. EXAMPLES: @@ -4092,7 +4091,7 @@ def density(self): if n < 2: return Rational(0) if self._directed: - return Rational(self.size()) / Rational((n ** 2 - n)) + return Rational(self.size()) / Rational(n ** 2 - n) return Rational(self.size()) / Rational((n ** 2 - n) / 2) def is_bipartite(self, certificate=False): @@ -18894,8 +18893,8 @@ def to_simple(self, to_undirected=True, keep_label='any', immutable=None): .. WARNING:: ``'min'`` and ``'max'`` only works if the labels can be compared. A - ``TypeError`` might be raised when working with non-comparable - objects in Python 3. + :class:`TypeError` might be raised when working with non-comparable + objects. - ``immutable`` -- boolean (default: ``Non``); whether to create a mutable/immutable copy. ``immutable=None`` (default) means that the @@ -25341,7 +25340,7 @@ def graph_isom_equivalent_non_edge_labeled_graph(g, partition=None, standard_lab for el, part in edge_partition: # The multiplicity of a label is the number of edges from u to v # it represents - m = sum((y[1] for y in el)) + m = sum(y[1] for y in el) if m in tmp: tmp[m].append(part) else: diff --git a/src/sage/graphs/graph.py b/src/sage/graphs/graph.py index 8988765d767..adc3c39f43e 100644 --- a/src/sage/graphs/graph.py +++ b/src/sage/graphs/graph.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Undirected graphs @@ -3285,8 +3284,8 @@ def bounded_outdegree_orientation(self, bound, solver=None, verbose=False, OUTPUT: - A DiGraph representing the orientation if it exists. A ``ValueError`` - exception is raised otherwise. + A DiGraph representing the orientation if it exists. + A :class:`ValueError` exception is raised otherwise. ALGORITHM: diff --git a/src/sage/graphs/graph_decompositions/modular_decomposition.py b/src/sage/graphs/graph_decompositions/modular_decomposition.py index 7a0c71c2fb1..c994475bd6b 100644 --- a/src/sage/graphs/graph_decompositions/modular_decomposition.py +++ b/src/sage/graphs/graph_decompositions/modular_decomposition.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Modular Decomposition diff --git a/src/sage/graphs/graph_generators.py b/src/sage/graphs/graph_generators.py index 0677028e451..3ba5dc6e91f 100644 --- a/src/sage/graphs/graph_generators.py +++ b/src/sage/graphs/graph_generators.py @@ -475,7 +475,7 @@ def wrap_name(x): from . import graph -class GraphGenerators(): +class GraphGenerators: r""" A class consisting of constructors for several common graphs, as well as orderly generation of isomorphism class representatives. See the diff --git a/src/sage/graphs/graph_input.py b/src/sage/graphs/graph_input.py index 193afc9c4eb..4e08af6a4fc 100644 --- a/src/sage/graphs/graph_input.py +++ b/src/sage/graphs/graph_input.py @@ -559,7 +559,7 @@ def from_dict_of_lists(G, D, loops=False, multiedges=False, weighted=False): for u in D: if len(set(D[u])) != len(D[u]): if multiedges is False: - v = next((v for v in D[u] if D[u].count(v) > 1)) + v = next(v for v in D[u] if D[u].count(v) > 1) raise ValueError("non-multigraph got several edges (%s, %s)" % (u, v)) multiedges = True break diff --git a/src/sage/graphs/graph_latex.py b/src/sage/graphs/graph_latex.py index 1cd878bec5a..bff200a1a86 100644 --- a/src/sage/graphs/graph_latex.py +++ b/src/sage/graphs/graph_latex.py @@ -625,7 +625,7 @@ def set_option(self, option_name, option_value=None): - ``option_name`` -- a string for a latex option contained in the list ``sage.graphs.graph_latex.GraphLatex.__graphlatex_options``. - A ``ValueError`` is raised if the option is not allowed. + A :class:`ValueError` is raised if the option is not allowed. - ``option_value`` -- a value for the option. If omitted, or set to ``None``, the option will use the default value. diff --git a/src/sage/graphs/hypergraph_generators.py b/src/sage/graphs/hypergraph_generators.py index 4291e024001..f5218e225f1 100644 --- a/src/sage/graphs/hypergraph_generators.py +++ b/src/sage/graphs/hypergraph_generators.py @@ -32,7 +32,7 @@ """ -class HypergraphGenerators(): +class HypergraphGenerators: r""" A class consisting of constructors for common hypergraphs. """ diff --git a/src/sage/graphs/lovasz_theta.py b/src/sage/graphs/lovasz_theta.py index 49bc7e32092..5335a597ebf 100644 --- a/src/sage/graphs/lovasz_theta.py +++ b/src/sage/graphs/lovasz_theta.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Lovász theta-function of graphs diff --git a/src/sage/graphs/pq_trees.py b/src/sage/graphs/pq_trees.py index 2ddd39691e8..68063bc8e73 100644 --- a/src/sage/graphs/pq_trees.py +++ b/src/sage/graphs/pq_trees.py @@ -558,7 +558,7 @@ def set_contiguous(self, v): In any case, the sets containing ``v`` are contiguous when this function ends. If there is no possibility of doing so, the function - raises a ``ValueError`` exception. + raises a :class:`ValueError` exception. EXAMPLES: @@ -837,7 +837,7 @@ def set_contiguous(self, v): In any case, the sets containing ``v`` are contiguous when this function ends. If there is no possibility of doing so, the function - raises a ``ValueError`` exception. + raises a :class:`ValueError` exception. EXAMPLES: diff --git a/src/sage/graphs/schnyder.py b/src/sage/graphs/schnyder.py index 40f6d923656..b52dcff829a 100644 --- a/src/sage/graphs/schnyder.py +++ b/src/sage/graphs/schnyder.py @@ -555,7 +555,7 @@ def _compute_coordinates(g, x): g.set_pos(coordinates) # Setting _pos attribute to store coordinates -class TreeNode(): +class TreeNode: """ A class to represent each node in the trees used by ``_realizer`` and ``_compute_coordinates`` when finding a planar geometric embedding in diff --git a/src/sage/graphs/tutte_polynomial.py b/src/sage/graphs/tutte_polynomial.py index e82150eeb9c..4868577c892 100644 --- a/src/sage/graphs/tutte_polynomial.py +++ b/src/sage/graphs/tutte_polynomial.py @@ -218,7 +218,7 @@ def edge_multiplicities(G): ######## -class Ear(): +class Ear: r""" An ear is a sequence of vertices @@ -372,7 +372,7 @@ def removed_from(self, G): ################## -class EdgeSelection(): +class EdgeSelection: pass