MerrimanInd / drawpyo

A Python library for programmatically generating Draw.io charts.
https://pypi.org/project/drawpyo/
MIT License
235 stars 14 forks source link

Typo: File leaked in drawpyo.File.write() #35

Closed tyhdefu closed 4 months ago

tyhdefu commented 4 months ago

ResourceWarning: unclosed file <_io.TextIOWrapper name='test_out\\extra\\Scenario3.5\\plx_253114.drawio' mode='w' encoding='utf-8'>

This appears to be due to you missing brackets: file.close vs file.close() https://github.com/MerrimanInd/drawpyo/blob/ec35335391178ee96fa5f96e2d4d782ed62dbf26/src/drawpyo/file.py#L139

It might also be a good opportunity to instead use with, which automatically closes the file for you.

with open(path.join(self.file_path, self.file_name), write_mode, encoding="utf-8") as f:
    f.write(self.xml)

Thank you for this great library - it has been hugely helpful.

MerrimanInd commented 4 months ago

Thanks for this catch! A little embarassed that slipped through the cracks. But I should be able to get a fix out this weekend.

MerrimanInd commented 4 months ago

Merged the PR, it'll be in the next release!

MerrimanInd commented 3 months ago

This fix is in version 0.2, thanks!