FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-125542: Deprecate `prefix_chars` in `ArgumentParser.add_argument_group` by savannahostrowski · Pull Request #125563 · python/cpython · GitHub

/ cpython Public
Merged
9 changes: 7 additions & 2 deletions Doc/deprecations/pending-removal-in-future.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
4 changes: 4 additions & 0 deletions Doc/library/argparse.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,10 @@ Argument groups
The function exists on the API by accident through inheritance and
will be removed in the future.

.. deprecated:: 3.14
Passing prefix_chars_ to :meth:`add_argument_group`
Comment thread
savannahostrowski marked this conversation as resolved.
is now deprecated.


Mutual exclusion
^^^^^^^^^^^^^^^^
Expand Down
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.14.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ asyncio
Deprecated
==========

* :mod:`argparse`:
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`:
:func:`!asyncio.iscoroutinefunction` is deprecated
and will be removed in Python 3.16,
Expand Down
8 changes: 8 additions & 0 deletions Lib/argparse.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,14 @@ def _check_help(self, action):
class _ArgumentGroup(_ActionsContainer):

def __init__(self, container, title=None, description=None, **kwargs):
if 'prefix_chars' in kwargs:
import warnings
depr_msg = (
"The use of the undocumented 'prefix_chars' parameter in "
"ArgumentParser.add_argument_group() is deprecated."
)
warnings.warn(depr_msg, DeprecationWarning, stacklevel=3)

# add any missing keyword arguments by checking the container
update = kwargs.setdefault
update('conflict_handler', container.conflict_handler)
Expand Down
25 changes: 25 additions & 0 deletions Lib/test/test_argparse.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,31 @@ def test_interleaved_groups(self):
result = parser.parse_args('1 2 3 4'.split())
self.assertEqual(expected, result)

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."
)
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):
Comment thread
savannahostrowski marked this conversation as resolved.
# "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."
)
with self.assertWarns(DeprecationWarning) as cm:
parser.add_argument_group(prefix_chars='-')
self.assertEqual(msg, str(cm.warning))
self.assertEqual(cm.filename, __file__)

# ===================
# Parent parser tests
# ===================
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Deprecate passing keyword-only *prefix_chars* argument to
:meth:`argparse.ArgumentParser.add_argument_group`.

Back | FazBrowse Home | New Git URL