mpcabd / python-arabic-reshaper

Reconstruct Arabic sentences to be used in applications that don't support Arabic
MIT License
395 stars 81 forks source link

ResourceWarning: __init__.py #57

Closed fbernhart closed 3 years ago

fbernhart commented 3 years ago

Opening a file - without closing it later - will keep the file open. By using "with-as" this won't happen.

Reason I'm submitting this PR: Whenever I run "import arabic_reshaper" in my scripts together with -W default -X tracemalloc=25 as arguments for Python, it'll show me that there is a ResourceWarning in your ini.py file.

C:\Users\XXX\Desktop\test\lib\site-packages\arabic_reshaper__init.py:12: ResourceWarning: unclosed file <_io.TextIOWrapper name='C:\Users\XXX\Desktop\test\lib\site-packages\arabic_reshaper\version.py' mode='r' encoding='cp1252'> exec(open(os.path.join(os.path.dirname(file), 'version.py')).read()) Object allocated at (most recent call last): File "C:/Users/XXX/Desktop/test/scratch.py", lineno 3 import arabic_reshaper File "", lineno 991 File "", lineno 975 File "", lineno 671 File "", lineno 783 File "", lineno 219 File "C:\Users\XXX\Desktop\test\lib\site-packages\arabic_reshaper\init.py", lineno 12 exec(open(os.path.join(os.path.dirname(file), 'version__.py')).read())

quinox commented 3 years ago

I run all my projects with the env PYTHONWARNINGS=default (to catch problems in my own code); I also see this ResourceWarning in my console, this PR fixes it for me