diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-06-26 10:16:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-26 10:16:19 (GMT) |
commit | 6bc7e2cca546c11e2b807068a4a612d0d902da11 (patch) | |
tree | 374d556e5636337664110c374687daa47e28a676 /Lib/argparse.py | |
parent | f2b4f517b9a0dbe4d2ebd1e1912615ede46d7aec (diff) | |
download | cpython-6bc7e2cca546c11e2b807068a4a612d0d902da11.zip cpython-6bc7e2cca546c11e2b807068a4a612d0d902da11.tar.gz cpython-6bc7e2cca546c11e2b807068a4a612d0d902da11.tar.bz2 |
[3.13] gh-121018: Ensure ArgumentParser.parse_args with exit_on_error=False raises instead of exiting when given unrecognized arguments (GH-121019) (GH-121032)
(cherry picked from commit 0654336dd5138aec04e3017e15ccbb90a44e053d)
Co-authored-by: blhsing <blhsing@gmail.com>
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r-- | Lib/argparse.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py index 55bf8cd..64893b5 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -1871,8 +1871,10 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): def parse_args(self, args=None, namespace=None): args, argv = self.parse_known_args(args, namespace) if argv: - msg = _('unrecognized arguments: %s') - self.error(msg % ' '.join(argv)) + msg = _('unrecognized arguments: %s') % ' '.join(argv) + if self.exit_on_error: + self.error(msg) + raise ArgumentError(None, msg) return args def parse_known_args(self, args=None, namespace=None): |