Opened 6 years ago
Closed 5 years ago
#13132 closed defect (fixed)
Small string formatting bug in Graph.delete_vertex
Reported by: | tjolivet | Owned by: | jason, ncohen, rlm |
---|---|---|---|
Priority: | major | Milestone: | sage-5.3 |
Component: | graph theory | Keywords: | |
Cc: | Merged in: | sage-5.3.beta2 | |
Authors: | David Coudert | Reviewers: | Timo Jolivet |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
If we remove a vertex which is a tuple from a graph which does not contain this vertex, Sage fails because it raises a TypeError
instead of the usual RuntimeError: Vertex (1) not in the graph.
sage: G = Graph() sage: G.delete_vertex((1,'a')) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /home/jaje/e_one_star/<ipython console> in <module>() /home/jaje/sage-5.0.1/local/lib/python2.7/site-packages/sage/graphs/generic_graph.pyc in delete_vertex(self, vertex, in_order) 7247 vertex = self.vertices()[vertex] 7248 if vertex not in self: -> 7249 raise RuntimeError("Vertex (%s) not in the graph."%vertex) 7250 7251 attributes_to_update = ('_pos', '_assoc', '_embedding') TypeError: not all arguments converted during string formatting
This is because the source code reads
raise RuntimeError("Vertex (%s) not in the graph."%vertex)
so it fails if vertex
is a tuple (too many values to unpack for the %s
), as illustrated here:
sage: "BLA%sBLA"%(1,'a') --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /home/jaje/e_one_star/<ipython console> in <module>() TypeError: not all arguments converted during string formatting sage: "BLA%sBLA"%str((1,'a')) "BLA(1, 'a')BLA"
I guess this bug can just be corrected by replacing all the occurrences of %vertex
by %str(vertex)
. It also occurs in DiGraph.delete_vertex
.
Attachments (1)
Change History (6)
Changed 5 years ago by
comment:1 Changed 5 years ago by
- Status changed from new to needs_review
comment:2 Changed 5 years ago by
- Reviewers set to Timo Jolivet
- Status changed from needs_review to positive_review
comment:3 Changed 5 years ago by
Thanks!
comment:4 Changed 5 years ago by
You are welcome.
comment:5 Changed 5 years ago by
- Merged in set to sage-5.3.beta2
- Resolution set to fixed
- Status changed from positive_review to closed
Note: See
TracTickets for help on using
tickets.
This patch solves the problem for Graph and DiGraph? since the function is in
generic_graph.py
. Thedelete_vertices
also add the same bug.