izimobil / polib

Pure python library to manipulate, create, modify gettext files (pot, po and mo files).
MIT License
102 stars 29 forks source link

[BUG] parser doesn't close file when an IOError error is raising #111

Closed fernandahf closed 1 year ago

fernandahf commented 3 years ago

Reproduced in py3.8 and py3.9

Following python warning is appearing in PO files with errors:

/home/travis/build/OCA/pylint-odoo/.tox/pylint/lib/python3.9/site-packages/polib.py:1474: ResourceWarning: unclosed file <_io.FileIO name='/home/travis/build/OCA/pylint-odoo/pylint_odoo/test_repo/broken_module2/i18n/en.po' mode='rb' closefd=True>

Above is because code is raising errors while is parsing in the following lines:

https://github.com/izimobil/polib/blob/8e1a86ec9bcab8356bc278666bdb170dec4ad6a2/polib.py#L1434-L1435

And code doesn't reach lines where the file is closed:

https://github.com/izimobil/polib/blob/8e1a86ec9bcab8356bc278666bdb170dec4ad6a2/polib.py#L1460-L1461

I think, file has to be closed regardless if has errors or not

fernandahf commented 3 years ago

FYI

@moylop260