mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-46510: update Python2-style exception handling in argparse (GH-30881)
This commit is contained in:
parent
ee60550e9b
commit
45f5f52601
1 changed files with 4 additions and 6 deletions
|
@ -1875,8 +1875,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||||
if self.exit_on_error:
|
if self.exit_on_error:
|
||||||
try:
|
try:
|
||||||
namespace, args = self._parse_known_args(args, namespace)
|
namespace, args = self._parse_known_args(args, namespace)
|
||||||
except ArgumentError:
|
except ArgumentError as err:
|
||||||
err = _sys.exc_info()[1]
|
|
||||||
self.error(str(err))
|
self.error(str(err))
|
||||||
else:
|
else:
|
||||||
namespace, args = self._parse_known_args(args, namespace)
|
namespace, args = self._parse_known_args(args, namespace)
|
||||||
|
@ -2151,8 +2150,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||||
arg_strings.append(arg)
|
arg_strings.append(arg)
|
||||||
arg_strings = self._read_args_from_files(arg_strings)
|
arg_strings = self._read_args_from_files(arg_strings)
|
||||||
new_arg_strings.extend(arg_strings)
|
new_arg_strings.extend(arg_strings)
|
||||||
except OSError:
|
except OSError as err:
|
||||||
err = _sys.exc_info()[1]
|
|
||||||
self.error(str(err))
|
self.error(str(err))
|
||||||
|
|
||||||
# return the modified argument list
|
# return the modified argument list
|
||||||
|
@ -2502,9 +2500,9 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||||
result = type_func(arg_string)
|
result = type_func(arg_string)
|
||||||
|
|
||||||
# ArgumentTypeErrors indicate errors
|
# ArgumentTypeErrors indicate errors
|
||||||
except ArgumentTypeError:
|
except ArgumentTypeError as err:
|
||||||
name = getattr(action.type, '__name__', repr(action.type))
|
name = getattr(action.type, '__name__', repr(action.type))
|
||||||
msg = str(_sys.exc_info()[1])
|
msg = str(err)
|
||||||
raise ArgumentError(action, msg)
|
raise ArgumentError(action, msg)
|
||||||
|
|
||||||
# TypeErrors or ValueErrors also indicate errors
|
# TypeErrors or ValueErrors also indicate errors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue