diff mbox series

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

Message ID 20200922223525.4085762-4-jsnow@redhat.com
State New
Headers show
Series qapi: static typing conversion, pt5 | expand

Commit Message

John Snow Sept. 22, 2020, 10:35 p.m. UTC
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 mbox series

Patch

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"