Use with instead of closing manually

This commit is contained in:
Kovid Goyal 2022-01-14 21:12:08 +05:30
parent 47dbaac54f
commit 8bb2da3c37
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -449,9 +449,8 @@ def process_single_item(
file_removed = False
try:
if isinstance(item, bytes):
tf = NamedTemporaryFile(prefix='stdin-image-data-', delete=False)
tf.write(item)
tf.close()
with NamedTemporaryFile(prefix='stdin-image-data-', delete=False) as tf:
tf.write(item)
item = tf.name
is_tempfile = True
if url_pat is not None and url_pat.match(item) is not None: