There were two problems with using pathlib.unlink here:
1. If the caller did not pass in a value for `dst`, it was assigned to the
second return value of a `tempfile.mkstemp` call. That is, `dst` would be a
string, not a `pathlib.Path`, and calling `.unlink()` would fail
cryptically.
2. The `missing_ok` parameter which this code was using was only added to
`pathlib.unlink` in Python 3.8. The stated Python baseline for Graphviz
currently is Python 3.6. If this code was reached with Python < 3.8 it
would result in an exception, obscuring the original problem.
try:
subprocess.check_call(args)
except subprocess.CalledProcessError:
- dst.unlink(missing_ok=True)
+ try:
+ os.remove(dst)
+ except FileNotFoundError:
+ pass
raise
return dst