]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-134970: Fix exception message in argparse module (GH-134971)
authorMichał Górny <mgorny@gentoo.org>
Sun, 1 Jun 2025 05:56:56 +0000 (07:56 +0200)
committerGitHub <noreply@github.com>
Sun, 1 Jun 2025 05:56:56 +0000 (08:56 +0300)
Fix the "unknown action" exception in argparse.ArgumentParser.add_argument_group()
to correctly replace the action class.

Lib/argparse.py
Misc/NEWS.d/next/Library/2025-05-31-12-08-12.gh-issue-134970.lgSaxq.rst [new file with mode: 0644]

index d1a6350c3fda6d324c826192672e3df3ff877f8e..83258cf3e0f37d0e0b3e4a6d0cadf021199d705d 100644 (file)
@@ -1534,7 +1534,7 @@ class _ActionsContainer(object):
         action_name = kwargs.get('action')
         action_class = self._pop_action_class(kwargs)
         if not callable(action_class):
-            raise ValueError('unknown action {action_class!r}')
+            raise ValueError(f'unknown action {action_class!r}')
         action = action_class(**kwargs)
 
         # raise an error if action for positional argument does not
diff --git a/Misc/NEWS.d/next/Library/2025-05-31-12-08-12.gh-issue-134970.lgSaxq.rst b/Misc/NEWS.d/next/Library/2025-05-31-12-08-12.gh-issue-134970.lgSaxq.rst
new file mode 100644 (file)
index 0000000..20f5356
--- /dev/null
@@ -0,0 +1,3 @@
+Fix the "unknown action" exception in
+:meth:`argparse.ArgumentParser.add_argument_group` to correctly replace the
+action class.