[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
- [PATCH 00/26] qapi: static typing conversion, pt5, John Snow, 2020/09/22
- [PATCH 03/26] qapi/parser.py: use 'with' statement for opening files,
John Snow <=
- [PATCH 02/26] qapi/parser.py: group variable declarations in __init__, John Snow, 2020/09/22
- [PATCH 04/26] qapi/source.py: Add default arguments to QAPISourceInfo, John Snow, 2020/09/22
- [PATCH 01/26] qapi/parser.py: refactor parsing routine into method, John Snow, 2020/09/22
- [PATCH 05/26] qapi/parser.py: start source info at line 0, John Snow, 2020/09/22
- [PATCH 07/26] qapi/parser.py: fully remove 'null' constant, John Snow, 2020/09/22
- [PATCH 08/26] qapi/parser.py: Assert lexer value is a string, John Snow, 2020/09/22
- [PATCH 06/26] qapi/parser.py: raise QAPIParseError during file opening, John Snow, 2020/09/22
- [PATCH 09/26] qapi/parser.py: assert get_expr returns object in outer loop, John Snow, 2020/09/22
- [PATCH 10/26] qapi/parser.py: assert object keys are strings, John Snow, 2020/09/22
- [PATCH 11/26] qapi/parser.py: Convert several methods to @classmethod, John Snow, 2020/09/22