Fix error on output due to mismatched byte/str #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the issue reported in #25 and the explanation justifies a PR.
We either output the generated graph as a
str
ing or render it tobytes
(png,pdf).An output stream either accepts bytes or strings, so step 1 was to encode the
str
tobytes
to make a consistent output.Next issue is that using an
argparse.FileType
withwb
leads to insonsistent file types.Nothing and
-
are interpreted assys.stdout
, which acceptstr
(utf-8).Passing a file results in a buffer that accepts
bytes
.This was fixed in newer versions of python.
The workaround I found was to conditionally write to use
args.outfile.write
for opened files andargs.outfile.buffer.write
for stdout.I just realized that there it is possible to directly specify
default=sys.stdout.buffer
in the parser. This then consistently leads toargs.outfile
always being a byte-writable buffer.