Dear PyMuPDF team,
fitz/utils.py contains the code warnings.simplefilter("once") in line 7. When importing fitz, fitz.utils is imported in turn and this code gets executed.
As a side effect of this, warning filtering behaviour of the Python runtime is changed for everything that comes afterwards:
# foo.py
never_gets_closed = open('foo.txt', 'w')
On exit, an unclosed-file-warning gets is issued, but _not_ displayed (default behaviour):
$ python3.7 foo.py # produces no output
fitz# bar.py
import fitz # this changes warning filtering
never_gets_closed = open('bar.txt', 'w')
On exit, an unclosed-file-warning gets is issued, _and_ displayed.
$ python3.7 bar.py
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='foo.txt' mode='w' encoding='UTF-8'>
This globally changed behaviour can become quite annoying when PyMuPDF is combined with other libraries that issue a lot of warnings (silenced by default). Of course the filter can be changed after importing fitz, but I would prefer if I didn't have to.
Regards & thanks for a great Library,
Bernhard
Thanks for reporting this!
Will be changed with the next version.
uploaded new version 1.14.20 addressing this
Thank you for the quick response & new version- that's awesome!
Most helpful comment
Thanks for reporting this!
Will be changed with the next version.