Skip to content

Commit 5dba04e

Browse files
authored
ResourceWarning: __init__.py (#57)
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())
1 parent 97b784d commit 5dba04e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

arabic_reshaper/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
ENABLE_ALL_LIGATURES)
1010

1111

12-
exec(open(os.path.join(os.path.dirname(__file__), '__version__.py')).read())
12+
with open(os.path.join(os.path.dirname(__file__), '__version__.py')) as fh:
13+
exec(fh.read())

0 commit comments

Comments
 (0)