qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 03/26] qapi/parser.py: use 'with' statement for opening files


From: John Snow
Subject: [PATCH 03/26] qapi/parser.py: use 'with' statement for opening files
Date: Tue, 22 Sep 2020 18:35:02 -0400

Minor, this prevents file descriptor leaks on error pathways.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 scripts/qapi/parser.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index b2984c8ff0..d0f35fe03e 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -64,8 +64,8 @@ def __init__(self, fname, previously_included=None, 
incl_info=None):
 
         # Showtime!
         try:
-            fp = open(self._fname, 'r', encoding='utf-8')
-            self.src = fp.read()
+            with open(self._fname, 'r', encoding='utf-8') as fp:
+                self.src = fp.read()
         except IOError as e:
             raise QAPISemError(incl_info or QAPISourceInfo(None, None, None),
                                "can't read %s file '%s': %s"
-- 
2.26.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]