[Python-checkins] bpo-46510: update Python2-style exception handling in argparse (GH-30881)
iritkatriel
webhook-mailer at python.org
Tue Jan 25 10:34:17 EST 2022
https://github.com/python/cpython/commit/45f5f52601ebccb195c19cb0a77beaf7f7dfa56a
commit: 45f5f52601ebccb195c19cb0a77beaf7f7dfa56a
branch: main
author: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>
committer: iritkatriel <1055913+iritkatriel at users.noreply.github.com>
date: 2022-01-25T15:34:03Z
summary:
bpo-46510: update Python2-style exception handling in argparse (GH-30881)
files:
M Lib/argparse.py
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 9344dab3e60d5..3c6aa3c991bfd 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -1875,8 +1875,7 @@ def parse_known_args(self, args=None, namespace=None):
if self.exit_on_error:
try:
namespace, args = self._parse_known_args(args, namespace)
- except ArgumentError:
- err = _sys.exc_info()[1]
+ except ArgumentError as err:
self.error(str(err))
else:
namespace, args = self._parse_known_args(args, namespace)
@@ -2151,8 +2150,7 @@ def _read_args_from_files(self, arg_strings):
arg_strings.append(arg)
arg_strings = self._read_args_from_files(arg_strings)
new_arg_strings.extend(arg_strings)
- except OSError:
- err = _sys.exc_info()[1]
+ except OSError as err:
self.error(str(err))
# return the modified argument list
@@ -2502,9 +2500,9 @@ def _get_value(self, action, arg_string):
result = type_func(arg_string)
# ArgumentTypeErrors indicate errors
- except ArgumentTypeError:
+ except ArgumentTypeError as err:
name = getattr(action.type, '__name__', repr(action.type))
- msg = str(_sys.exc_info()[1])
+ msg = str(err)
raise ArgumentError(action, msg)
# TypeErrors or ValueErrors also indicate errors
More information about the Python-checkins
mailing list