https://github.com/python/cpython/commit/da090f1658e72485b201507653f6d673f3e39c86
commit: da090f1658e72485b201507653f6d673f3e39c86
branch: main
author: Nikita Sobolev <[email protected]>
committer: sobolevn <[email protected]>
date: 2024-05-09T11:46:45Z
summary:

gh-118805: Remove type, choices, metavar params of `BooleanOptionalAction` 
(#118806)

Co-authored-by: Alex Waygood <[email protected]>

files:
A Misc/NEWS.d/next/Library/2024-05-09-01-05-52.gh-issue-118805.N7dm07.rst
M Doc/whatsnew/3.14.rst
M Lib/argparse.py
M Lib/test/test_argparse.py

diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst
index 24b6b617fe17dc..25c43dc0387eaf 100644
--- a/Doc/whatsnew/3.14.rst
+++ b/Doc/whatsnew/3.14.rst
@@ -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
 -----
 
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 55bf8cdd875a8d..cdd29d3ad568e5 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -831,19 +831,13 @@ def __call__(self, parser, namespace, values, 
option_string=None):
         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 @@ def __init__(self,
                 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)
 
 
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index 02b499145f6c43..eb1a9f5146beb4 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -765,49 +765,6 @@ def test_const(self):
 
         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
index 00000000000000..4f1db04d8bd67f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-05-09-01-05-52.gh-issue-118805.N7dm07.rst
@@ -0,0 +1,3 @@
+Remove *type*, *choices*, and *metavar* parameters of
+:class:`!argparse.BooleanOptionalAction`.
+They were deprecated since Python 3.12.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to