Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceWarning: __init__.py #57

Merged
merged 1 commit into from
Nov 4, 2020
Merged

ResourceWarning: __init__.py #57

merged 1 commit into from
Nov 4, 2020

Conversation

fbernhart
Copy link
Contributor

@fbernhart fbernhart commented Oct 6, 2020

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())

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 RecourseWarning 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 "<frozen importlib._bootstrap>", lineno 991
  File "<frozen importlib._bootstrap>", lineno 975
  File "<frozen importlib._bootstrap>", lineno 671
  File "<frozen importlib._bootstrap_external>", lineno 783
  File "<frozen importlib._bootstrap>", 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
Copy link

quinox commented Nov 4, 2020

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

@mpcabd mpcabd merged commit 5dba04e into mpcabd:master Nov 4, 2020
@fbernhart fbernhart deleted the patch-1 branch November 4, 2020 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants