]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118805: Remove type, choices, metavar params of `BooleanOptionalAction` (#118806)
authorNikita Sobolev <mail@sobolevn.me>
Thu, 9 May 2024 11:46:45 +0000 (14:46 +0300)
committerGitHub <noreply@github.com>
Thu, 9 May 2024 11:46:45 +0000 (11:46 +0000)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Doc/whatsnew/3.14.rst
Lib/argparse.py
Lib/test/test_argparse.py
Misc/NEWS.d/next/Library/2024-05-09-01-05-52.gh-issue-118805.N7dm07.rst [new file with mode: 0644]

index 24b6b617fe17dc973076d89508f781613dea51fa..25c43dc0387eaf7c3a260118315fc52318ff8922 100644 (file)
@@ -101,6 +101,13 @@ Deprecated
 Removed
 =======
 
+argparse
+--------
+
+* The *type*, *choices*, and *metavar* parameters
+  of :class:`!argparse.BooleanOptionalAction` are removed.
+  They were deprecated since 3.12.
+
 email
 -----
 
index 55bf8cdd875a8d866801eeb5e5ea0eb0f6df071a..cdd29d3ad568e5592fe0d516260388506d1184eb 100644 (file)
@@ -831,19 +831,13 @@ class Action(_AttributeHolder):
         raise NotImplementedError(_('.__call__() not defined'))
 
 
-# FIXME: remove together with `BooleanOptionalAction` deprecated arguments.
-_deprecated_default = object()
-
 class BooleanOptionalAction(Action):
     def __init__(self,
                  option_strings,
                  dest,
                  default=None,
-                 type=_deprecated_default,
-                 choices=_deprecated_default,
                  required=False,
                  help=None,
-                 metavar=_deprecated_default,
                  deprecated=False):
 
         _option_strings = []
@@ -854,35 +848,13 @@ class BooleanOptionalAction(Action):
                 option_string = '--no-' + option_string[2:]
                 _option_strings.append(option_string)
 
-        # We need `_deprecated` special value to ban explicit arguments that
-        # match default value. Like:
-        #   parser.add_argument('-f', action=BooleanOptionalAction, type=int)
-        for field_name in ('type', 'choices', 'metavar'):
-            if locals()[field_name] is not _deprecated_default:
-                import warnings
-                warnings._deprecated(
-                    field_name,
-                    "{name!r} is deprecated as of Python 3.12 and will be "
-                    "removed in Python {remove}.",
-                    remove=(3, 14))
-
-        if type is _deprecated_default:
-            type = None
-        if choices is _deprecated_default:
-            choices = None
-        if metavar is _deprecated_default:
-            metavar = None
-
         super().__init__(
             option_strings=_option_strings,
             dest=dest,
             nargs=0,
             default=default,
-            type=type,
-            choices=choices,
             required=required,
             help=help,
-            metavar=metavar,
             deprecated=deprecated)
 
 
index 02b499145f6c431d2c840cda5a0af6b05382f48b..eb1a9f5146beb4f7b8577ae39c9e56cafc8f7526 100644 (file)
@@ -765,49 +765,6 @@ class TestBooleanOptionalAction(ParserTestCase):
 
         self.assertIn("got an unexpected keyword argument 'const'", str(cm.exception))
 
-    def test_deprecated_init_kw(self):
-        # See gh-92248
-        parser = argparse.ArgumentParser()
-
-        with self.assertWarns(DeprecationWarning):
-            parser.add_argument(
-                '-a',
-                action=argparse.BooleanOptionalAction,
-                type=None,
-            )
-        with self.assertWarns(DeprecationWarning):
-            parser.add_argument(
-                '-b',
-                action=argparse.BooleanOptionalAction,
-                type=bool,
-            )
-
-        with self.assertWarns(DeprecationWarning):
-            parser.add_argument(
-                '-c',
-                action=argparse.BooleanOptionalAction,
-                metavar=None,
-            )
-        with self.assertWarns(DeprecationWarning):
-            parser.add_argument(
-                '-d',
-                action=argparse.BooleanOptionalAction,
-                metavar='d',
-            )
-
-        with self.assertWarns(DeprecationWarning):
-            parser.add_argument(
-                '-e',
-                action=argparse.BooleanOptionalAction,
-                choices=None,
-            )
-        with self.assertWarns(DeprecationWarning):
-            parser.add_argument(
-                '-f',
-                action=argparse.BooleanOptionalAction,
-                choices=(),
-            )
-
 class TestBooleanOptionalActionRequired(ParserTestCase):
     """Tests BooleanOptionalAction required"""
 
diff --git a/Misc/NEWS.d/next/Library/2024-05-09-01-05-52.gh-issue-118805.N7dm07.rst b/Misc/NEWS.d/next/Library/2024-05-09-01-05-52.gh-issue-118805.N7dm07.rst
new file mode 100644 (file)
index 0000000..4f1db04
--- /dev/null
@@ -0,0 +1,3 @@
+Remove *type*, *choices*, and *metavar* parameters of
+:class:`!argparse.BooleanOptionalAction`.
+They were deprecated since Python 3.12.