From 41d67ce9807373ae42045a8c8f2f63f121b05e96 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 30 Oct 2024 01:07:43 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Savannah Ostrowski --- Lib/test/test_argparse.py | 10 +++++----- .../2024-10-28-11-33-59.gh-issue-126068.Pdznm_.rst | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 6a7ce0653d4bc0..9496c4817e50f2 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -2386,11 +2386,11 @@ def test_modified_invalid_action(self): action.type = () self.assertRaisesRegex(RuntimeError, r'\(\) is not callable', parser.parse_args, ['--foo', 'bar']) - # It is impossible to distinguish a TypeError raised due to mismatch - # of the required function arguments from a TypeError raised for wrong - # argument value, and it is not worth to use heavy inspect machinery - # which does not work in all cases anyway. - # So we get a dumb ArgumentError for such logical error. + # It is impossible to distinguish a TypeError raised due to a mismatch + # of the required function arguments from a TypeError raised for an incorrect + # argument value, and using the heavy inspection machinery is not worthwhile + # as it does not reliably work in all cases. + # Therefore, a generic ArgumentError is raised to handle this logical error. action.type = pow self.assertRaisesRegex(argparse.ArgumentError, "argument --foo: invalid pow value: 'bar'", diff --git a/Misc/NEWS.d/next/Library/2024-10-28-11-33-59.gh-issue-126068.Pdznm_.rst b/Misc/NEWS.d/next/Library/2024-10-28-11-33-59.gh-issue-126068.Pdznm_.rst index e38a5f6cc7d9dc..4883f409eb24b4 100644 --- a/Misc/NEWS.d/next/Library/2024-10-28-11-33-59.gh-issue-126068.Pdznm_.rst +++ b/Misc/NEWS.d/next/Library/2024-10-28-11-33-59.gh-issue-126068.Pdznm_.rst @@ -1,3 +1,4 @@ -Fix exceptions in the :mod:`argparse` module. Only error messages for -ArgumentError and ArgumentTypeError are now translated. ArgumentError is now -only used for command line errors, not for logical errors in the program. +Fix exceptions in the :mod:`argparse` module so that only error messages for +:exc:`ArgumentError` and :exc:`ArgumentTypeError` are now translated. +:exc:`ArgumentError` is now only used for command line errors, not for logical +errors in the program.