Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Doc/deprecations/pending-removal-in-future.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ Pending removal in future versions
The following APIs will be removed in the future,
although there is currently no date scheduled for their removal.

* :mod:`argparse`: Nesting argument groups and nesting mutually exclusive
groups are deprecated.
* :mod:`argparse`:

* Nesting argument groups and nesting mutually exclusive
groups are deprecated.
* Passing the undocumented keyword argument *prefix_chars* to
:meth:`~argparse.ArgumentParser.add_argument_group` is now
deprecated.

* :mod:`array`'s ``'u'`` format code (:gh:`57281`)

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,7 @@ Argument groups
The function exists on the API by accident through inheritance and
will be removed in the future.

.. versionchanged:: 3.14
.. deprecated:: 3.14
Passing prefix_chars_ to :meth:`add_argument_group`
is now deprecated.

Expand Down
5 changes: 3 additions & 2 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,9 @@ Deprecated
==========

* :mod:`argparse`:
Passing *prefix_chars* to :func:`argparse.add_argument_group`
is now deprecated.
Passing the undocumented keyword argument *prefix_chars* to
:meth:`~argparse.ArgumentParser.add_argument_group` is now
deprecated.
(Contributed by Savannah Ostrowski in :gh:`125563`.)

* :mod:`asyncio`:
Expand Down
2 changes: 1 addition & 1 deletion Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ def __init__(self, container, title=None, description=None, **kwargs):
import warnings
depr_msg = (
"The use of the undocumented 'prefix_chars' parameter in "
"ArgumentParser.add_argument_group is deprecated."
"ArgumentParser.add_argument_group() is deprecated."
)
warnings.warn(depr_msg, DeprecationWarning, stacklevel=3)

Expand Down
21 changes: 8 additions & 13 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2819,32 +2819,27 @@ def test_interleaved_groups(self):
class TestGroupConstructor(TestCase):
def test_group_prefix_chars(self):
parser = ErrorRaisingArgumentParser()

msg = (
"The use of the undocumented 'prefix_chars' parameter in "
"ArgumentParser.add_argument_group is deprecated."
"ArgumentParser.add_argument_group() is deprecated."
)
with self.assertWarnsRegex(DeprecationWarning, msg):
with self.assertWarns(DeprecationWarning) as cm:
parser.add_argument_group(prefix_chars='-+')
self.assertEqual(msg, str(cm.warning))
self.assertEqual(cm.filename, __file__)

def test_group_prefix_chars_default(self):
# "default" isn't quite the right word here, but it's the same as
# the parser's default prefix so it's a good test
parser = ErrorRaisingArgumentParser()

msg = (
"The use of the undocumented 'prefix_chars' parameter in "
"ArgumentParser.add_argument_group is deprecated."
"ArgumentParser.add_argument_group() is deprecated."
)

with self.assertWarnsRegex(DeprecationWarning, msg):
with self.assertWarns(DeprecationWarning) as cm:
parser.add_argument_group(prefix_chars='-')

def test_group_without_prefix_chars(self):
parser = ErrorRaisingArgumentParser()
group = parser.add_argument_group()
group.add_argument('--foo')
self.assertEqual(parser.parse_args(['--foo', 'bar']), NS(foo='bar'))
self.assertEqual(msg, str(cm.warning))
self.assertEqual(cm.filename, __file__)

# ===================
# Parent parser tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Deprecate passing prefix_chars_ parameter to :meth:`ArgumentParser.add_argument_group`.
Deprecate passing keyword-only ``prefix_chars`` argument to
:meth:`argparse.ArgumentParser.add_argument_group`.
Loading