Skip to content

Commit da090f1

Browse files
gh-118805: Remove type, choices, metavar params of BooleanOptionalAction (#118806)
Co-authored-by: Alex Waygood <[email protected]>
1 parent c68acb1 commit da090f1

File tree

4 files changed

+10
-71
lines changed

4 files changed

+10
-71
lines changed

Doc/whatsnew/3.14.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ Deprecated
101101
Removed
102102
=======
103103

104+
argparse
105+
--------
106+
107+
* The *type*, *choices*, and *metavar* parameters
108+
of :class:`!argparse.BooleanOptionalAction` are removed.
109+
They were deprecated since 3.12.
110+
104111
email
105112
-----
106113

Lib/argparse.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -831,19 +831,13 @@ def __call__(self, parser, namespace, values, option_string=None):
831831
raise NotImplementedError(_('.__call__() not defined'))
832832

833833

834-
# FIXME: remove together with `BooleanOptionalAction` deprecated arguments.
835-
_deprecated_default = object()
836-
837834
class BooleanOptionalAction(Action):
838835
def __init__(self,
839836
option_strings,
840837
dest,
841838
default=None,
842-
type=_deprecated_default,
843-
choices=_deprecated_default,
844839
required=False,
845840
help=None,
846-
metavar=_deprecated_default,
847841
deprecated=False):
848842

849843
_option_strings = []
@@ -854,35 +848,13 @@ def __init__(self,
854848
option_string = '--no-' + option_string[2:]
855849
_option_strings.append(option_string)
856850

857-
# We need `_deprecated` special value to ban explicit arguments that
858-
# match default value. Like:
859-
# parser.add_argument('-f', action=BooleanOptionalAction, type=int)
860-
for field_name in ('type', 'choices', 'metavar'):
861-
if locals()[field_name] is not _deprecated_default:
862-
import warnings
863-
warnings._deprecated(
864-
field_name,
865-
"{name!r} is deprecated as of Python 3.12 and will be "
866-
"removed in Python {remove}.",
867-
remove=(3, 14))
868-
869-
if type is _deprecated_default:
870-
type = None
871-
if choices is _deprecated_default:
872-
choices = None
873-
if metavar is _deprecated_default:
874-
metavar = None
875-
876851
super().__init__(
877852
option_strings=_option_strings,
878853
dest=dest,
879854
nargs=0,
880855
default=default,
881-
type=type,
882-
choices=choices,
883856
required=required,
884857
help=help,
885-
metavar=metavar,
886858
deprecated=deprecated)
887859

888860

Lib/test/test_argparse.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -765,49 +765,6 @@ def test_const(self):
765765

766766
self.assertIn("got an unexpected keyword argument 'const'", str(cm.exception))
767767

768-
def test_deprecated_init_kw(self):
769-
# See gh-92248
770-
parser = argparse.ArgumentParser()
771-
772-
with self.assertWarns(DeprecationWarning):
773-
parser.add_argument(
774-
'-a',
775-
action=argparse.BooleanOptionalAction,
776-
type=None,
777-
)
778-
with self.assertWarns(DeprecationWarning):
779-
parser.add_argument(
780-
'-b',
781-
action=argparse.BooleanOptionalAction,
782-
type=bool,
783-
)
784-
785-
with self.assertWarns(DeprecationWarning):
786-
parser.add_argument(
787-
'-c',
788-
action=argparse.BooleanOptionalAction,
789-
metavar=None,
790-
)
791-
with self.assertWarns(DeprecationWarning):
792-
parser.add_argument(
793-
'-d',
794-
action=argparse.BooleanOptionalAction,
795-
metavar='d',
796-
)
797-
798-
with self.assertWarns(DeprecationWarning):
799-
parser.add_argument(
800-
'-e',
801-
action=argparse.BooleanOptionalAction,
802-
choices=None,
803-
)
804-
with self.assertWarns(DeprecationWarning):
805-
parser.add_argument(
806-
'-f',
807-
action=argparse.BooleanOptionalAction,
808-
choices=(),
809-
)
810-
811768
class TestBooleanOptionalActionRequired(ParserTestCase):
812769
"""Tests BooleanOptionalAction required"""
813770

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove *type*, *choices*, and *metavar* parameters of
2+
:class:`!argparse.BooleanOptionalAction`.
3+
They were deprecated since Python 3.12.

0 commit comments

Comments
 (0)