Closed nyurik closed 2 years ago
Thanks for the report.
The underlying change in 0.18
is documented in https://graphviz.readthedocs.io/en/stable/changelog.html#version-0-18 as follows:
Change of undocumented behaviour: When iterating over a
Graph
,Digraph
, orSource
instance, the yielded lines now include a final newline ('\n'
). This mimics iteration over file object lines in text mode.
Also updated the relevant section on using .body
directly (https://graphviz.readthedocs.io/en/stable/manual.html#custom-dot-statements) that the final newline needs to be included:
To add arbitrary statements to the created DOT source, you can use the body attribute of
Graph
andDigraph
objects. It holds the verbatim list of (str
) lines to be written to the source file (including their final newline).
Looks like we should also update the docstring of the body
argument here:
Would this suffice? https://github.com/xflr6/graphviz/compare/body_newline
@xflr6 would it make sense to just automatically append a newline if its missing? Documentation keeps saying "line", but if the line is not \n
-terminated, it becomes concatenation -- an opposite of a "line" concept, which is almost never the desired result. I think to keep this as simple and surprise-free as possible, graphvis can just handle this edgecase, especially when it would be compatible with the prior versions. The fewer surprises we have with libs, the easier our life will be :)
SGTM assuming that we only change the behaviour or the body
argument (not the attribute).
Let me know in case you want to give it a try.
Closing #158 in favour of a the documentation fix proposed earlier since the former also changes the .body
attribute.
Pending fix in 77e5fcb703d02ba30c1cf81153fd0883c870c90b.
Fixed in 0.19.2
release, closing.
The change v0.17 -> 0.19.1 resulted in a breaking change that I couldn't find any documentation, and I'm not sure if it was intentional. A simple repo:
The resulting dot file produced with 0.17 (as expected):
The result with 0.19:
After some debugging - 0.17 used
"\n".join(body)
, whereas the new one usesfor line in body: write(line)
(via yield).