Skip to content

Commit 7cc2a4b

Browse files
author
Release Manager
committed
gh-36736: avoid importing `DiGraph` from `sage.graphs.graph` We remove the top level import of `DiGraph` from `src/sage/graphs/graph.py` to prevent using `from sage.graphs.graph import DiGraph`. ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #36736 Reported by: David Coudert Reviewer(s): Matthias Köppe
2 parents fc591d3 + 5560fa3 commit 7cc2a4b

File tree

9 files changed

+19
-14
lines changed

9 files changed

+19
-14
lines changed

src/sage/categories/coxeter_groups.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ def bruhat_interval_poset(self, x, y, facade=False):
10771077
nextlayer.add(t)
10781078
curlayer = nextlayer
10791079

1080-
from sage.graphs.graph import DiGraph
1080+
from sage.graphs.digraph import DiGraph
10811081
return Poset(DiGraph(d, format='dict_of_lists',
10821082
data_structure='static_sparse'),
10831083
cover_relations=True,
@@ -1163,7 +1163,7 @@ def bruhat_graph(self, x=None, y=None, edge_labels=False):
11631163
else:
11641164
d.append((u, v))
11651165

1166-
from sage.graphs.graph import DiGraph
1166+
from sage.graphs.digraph import DiGraph
11671167
return DiGraph(d)
11681168

11691169
def canonical_representation(self):

src/sage/combinat/binary_tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ def graph(self, with_leaves=True):
748748
sage: t1.graph(with_leaves=False).edges(sort=True)
749749
[(0, 1, None), (0, 2, None), (2, 3, None), (2, 4, None)]
750750
"""
751-
from sage.graphs.graph import DiGraph
751+
from sage.graphs.digraph import DiGraph
752752

753753
if with_leaves: # We want leaves and nodes.
754754

src/sage/geometry/lattice_polytope.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131
is_PointCollection,
132132
read_palp_point_collection)
133133
from sage.geometry.toric_lattice import ToricLattice, is_ToricLattice
134-
from sage.graphs.graph import DiGraph, Graph
135134
from sage.groups.perm_gps.permgroup_named import SymmetricGroup
136135

137136
from sage.misc.lazy_import import lazy_import
@@ -2058,6 +2057,7 @@ def LPFace(vertices, facets):
20582057
else:
20592058
# Get face lattice as a sublattice of the ambient one
20602059
allowed_indices = frozenset(self._ambient_vertex_indices)
2060+
from sage.graphs.digraph import DiGraph
20612061
L = DiGraph()
20622062
empty = self._ambient.face_lattice().bottom()
20632063
L.add_vertex(0) # In case it is the only one
@@ -3966,6 +3966,7 @@ def skeleton(self):
39663966
sage: g.edges(sort=True) # needs palp sage.graphs
39673967
[(0, 1, None), (0, 3, None), (1, 2, None), (2, 3, None)]
39683968
"""
3969+
from sage.graphs.graph import Graph
39693970
skeleton = Graph()
39703971
skeleton.add_vertices(self.skeleton_points(1))
39713972
for edge in self.edges():

src/sage/graphs/bliss.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ cpdef canonical_form(G, partition=None, return_graph=False, use_edge_labels=True
579579

580580
if return_graph:
581581
if directed:
582-
from sage.graphs.graph import DiGraph
582+
from sage.graphs.digraph import DiGraph
583583
H = DiGraph(new_edges, loops=G.allows_loops(), multiedges=G.allows_multiple_edges())
584584
else:
585585
from sage.graphs.graph import Graph

src/sage/graphs/graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@
421421
from sage.rings.integer_ring import ZZ
422422
import sage.graphs.generic_graph_pyx as generic_graph_pyx
423423
from sage.graphs.generic_graph import GenericGraph
424-
from sage.graphs.digraph import DiGraph
425424
from sage.graphs.independent_sets import IndependentSets
426425
from sage.misc.rest_index_of_methods import doc_index, gen_thematic_rest_table_index
427426
from sage.graphs.views import EdgesView
@@ -3514,6 +3513,7 @@ def orientations(self, data_structure=None, sparse=None):
35143513
if name:
35153514
name = 'An orientation of ' + name
35163515

3516+
from sage.graphs.digraph import DiGraph
35173517
if not self.size():
35183518
D = DiGraph(data=[self.vertices(sort=False), []],
35193519
format='vertices_and_edges',

src/sage/graphs/graph_generators_pyx.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ def RandomGNP(n, p, bint directed=False, bint loops=False, seed=None):
6363
...
6464
ValueError: parameter 'loops' can be set to True only when 'directed' is True
6565
"""
66-
from sage.graphs.graph import Graph, DiGraph
67-
6866
if seed is not None:
6967
set_random_seed(seed)
7068

@@ -74,8 +72,10 @@ def RandomGNP(n, p, bint directed=False, bint loops=False, seed=None):
7472
cdef int pp = int(round(float(p * RAND_MAX_f)))
7573

7674
if directed:
75+
from sage.graphs.digraph import DiGraph
7776
G = DiGraph(loops=loops)
7877
else:
78+
from sage.graphs.graph import Graph
7979
G = Graph()
8080
if loops:
8181
raise ValueError("parameter 'loops' can be set to True only when 'directed' is True")

src/sage/schemes/elliptic_curves/ell_field.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,7 +1964,6 @@ class of curves. If the j-invariant is not unique in the isogeny
19641964
"""
19651965

19661966
from warnings import warn
1967-
from sage.graphs.graph import DiGraph, Graph
19681967
from sage.matrix.constructor import Matrix
19691968

19701969
# warn users if things are getting big
@@ -2016,8 +2015,13 @@ class of curves. If the j-invariant is not unique in the isogeny
20162015
labels.append(E._equation_string())
20172016

20182017
A = Matrix([r + [0] * (len(A) - len(r)) for r in A])
2019-
G = (DiGraph if directed else Graph)(A, format="adjacency_matrix",
2020-
data_structure="static_sparse")
2018+
if directed:
2019+
from sage.graphs.digraph import DiGraph as GraphType
2020+
else:
2021+
from sage.graphs.graph import Graph as GraphType
2022+
2023+
G = GraphType(A, format="adjacency_matrix",
2024+
data_structure="static_sparse")
20212025
# inplace relabelling is necessary for static_sparse graphs
20222026
GL = G.relabel(labels, inplace=False)
20232027
return GL

src/sage/sets/disjoint_set.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ cdef class DisjointSet_of_integers(DisjointSet_class):
600600
[(0, 0, None), (1, 1, None), (2, 1, None), (3, 1, None), (4, 1, None)]
601601
"""
602602
d = {i: [self._nodes.parent[i]] for i in range(self.cardinality())}
603-
from sage.graphs.graph import DiGraph
603+
from sage.graphs.digraph import DiGraph
604604
return DiGraph(d)
605605

606606
cdef class DisjointSet_of_hashables(DisjointSet_class):
@@ -891,5 +891,5 @@ cdef class DisjointSet_of_hashables(DisjointSet_class):
891891
e = self._int_to_el[i]
892892
p = self._int_to_el[self._nodes.parent[i]]
893893
d[e] = [p]
894-
from sage.graphs.graph import DiGraph
894+
from sage.graphs.digraph import DiGraph
895895
return DiGraph(d)

src/sage/sets/set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ def subsets_lattice(self):
813813
raise NotImplementedError(
814814
"this method is only implemented for finite sets")
815815
from sage.combinat.posets.lattices import FiniteLatticePoset
816-
from sage.graphs.graph import DiGraph
816+
from sage.graphs.digraph import DiGraph
817817
from sage.rings.integer import Integer
818818
n = self.cardinality()
819819
# list, contains at position 0 <= i < 2^n

0 commit comments

Comments
 (0)