mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
modernize some modules' code by using with statement around open()
This commit is contained in:
parent
fd6e6cfa29
commit
2f50aaf2ff
14 changed files with 50 additions and 89 deletions
|
@ -2010,16 +2010,13 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||
# replace arguments referencing files with the file content
|
||||
else:
|
||||
try:
|
||||
args_file = open(arg_string[1:])
|
||||
try:
|
||||
with open(arg_string[1:]) as args_file:
|
||||
arg_strings = []
|
||||
for arg_line in args_file.read().splitlines():
|
||||
for arg in self.convert_arg_line_to_args(arg_line):
|
||||
arg_strings.append(arg)
|
||||
arg_strings = self._read_args_from_files(arg_strings)
|
||||
new_arg_strings.extend(arg_strings)
|
||||
finally:
|
||||
args_file.close()
|
||||
except OSError:
|
||||
err = _sys.exc_info()[1]
|
||||
self.error(str(err))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue