Skip to content

Commit 5edd15e

Browse files
committed
encoding.read: fix ResourceWarning: unclosed file on some platforms
1 parent 24743b7 commit 5edd15e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

guidata/utils/encoding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ def read(filename: str, encoding: str = "utf-8") -> tuple[str, str]:
173173
Read text from file ('filename')
174174
Return text and encoding
175175
"""
176-
text, encoding = decode(open(filename, "rb").read())
176+
with open(filename, "rb") as file:
177+
text, encoding = decode(file.read())
177178
return text, encoding
178179

179180

0 commit comments

Comments
 (0)