WireViz
WireViz copied to clipboard
Avoid ResourceWarning: unclosed file
A number of such warnings showed up when running (with wireviz v0.4) e.g.
PYTHONWARNINGS=always python build_examples.py
PYTHONWARNINGS=always wireviz ../../examples/demo0?.yml
See https://github.com/wireviz/WireViz/pull/309#issuecomment-2170988381
Fix: All open()
calls should be in a "with open() as x
" statement to ensure closing the file when exiting the block in any way. Otherwise, use the new file_read_text()
or file_write_text()
thin wrapper functions to read or write the whole utf-8 text file and closing it.