Skip to content

Commit

Permalink
Apply suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Jan 16, 2024
1 parent 12d3bc9 commit 5f72bc6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ printed to standard error when the argument is used::
>>> parser.parse_args([])
Namespace(legs=0)
>>> parser.parse_args(['--legs', '4']) # doctest: +SKIP
snake.py: warning: usage of option '--legs' is deprecated
snake.py: warning: option '--legs' is deprecated
Namespace(legs=4)

.. versionchanged:: 3.13
Expand Down Expand Up @@ -1893,7 +1893,7 @@ Sub-commands
>>> run = subparsers.add_parser('run')
>>> fly = subparsers.add_parser('fly', deprecated=True)
>>> parser.parse_args(['fly']) # doctest: +SKIP
chicken.py: warning: usage of command 'fly' is deprecated
chicken.py: warning: command 'fly' is deprecated
Namespace()

.. versionadded:: 3.13
Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ ast
possible to obtain an optimized ``AST``.
(Contributed by Irit Katriel in :gh:`108113`).

argrapse
argparse
--------

* Add parameter *deprecated* in methods
Expand Down
6 changes: 3 additions & 3 deletions Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ def __call__(self, parser, namespace, values, option_string=None):
raise ArgumentError(self, msg)

if parser_name in self._deprecated:
parser._warning(_("usage of command '%(parser_name)s' is deprecated") %
parser._warning(_("command '%(parser_name)s' is deprecated") %
{'parser_name': parser_name})

# parse all the remaining options into the namespace
Expand Down Expand Up @@ -2107,7 +2107,7 @@ def consume_optional(start_index):
assert action_tuples
for action, args, option_string in action_tuples:
if action.deprecated and option_string not in warned:
self._warning(_("usage of option '%(option)s' is deprecated") %
self._warning(_("option '%(option)s' is deprecated") %
{'option': option_string})
warned.add(option_string)
take_action(action, args, option_string)
Expand All @@ -2130,7 +2130,7 @@ def consume_positionals(start_index):
args = arg_strings[start_index: start_index + arg_count]
start_index += arg_count
if args and action.deprecated and action.dest not in warned:
self._warning(_("usage of argument '%(argument_name)s' is deprecated") %
self._warning(_("argument '%(argument_name)s' is deprecated") %
{'argument_name': action.dest})
warned.add(action.dest)
take_action(action, args)
Expand Down
34 changes: 17 additions & 17 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5324,26 +5324,26 @@ def test_deprecated_option(self):
with captured_stderr() as stderr:
parser.parse_args(['--foo', 'spam'])
stderr = stderr.getvalue()
self.assertRegex(stderr, "warning: usage of option '--foo' is deprecated")
self.assertRegex(stderr, "warning: option '--foo' is deprecated")
self.assertEqual(stderr.count('is deprecated'), 1)

with captured_stderr() as stderr:
parser.parse_args(['-f', 'spam'])
stderr = stderr.getvalue()
self.assertRegex(stderr, "warning: usage of option '-f' is deprecated")
self.assertRegex(stderr, "warning: option '-f' is deprecated")
self.assertEqual(stderr.count('is deprecated'), 1)

with captured_stderr() as stderr:
parser.parse_args(['--foo', 'spam', '-f', 'ham'])
stderr = stderr.getvalue()
self.assertRegex(stderr, "warning: usage of option '--foo' is deprecated")
self.assertRegex(stderr, "warning: usage of option '-f' is deprecated")
self.assertRegex(stderr, "warning: option '--foo' is deprecated")
self.assertRegex(stderr, "warning: option '-f' is deprecated")
self.assertEqual(stderr.count('is deprecated'), 2)

with captured_stderr() as stderr:
parser.parse_args(['--foo', 'spam', '--foo', 'ham'])
stderr = stderr.getvalue()
self.assertRegex(stderr, "warning: usage of option '--foo' is deprecated")
self.assertRegex(stderr, "warning: option '--foo' is deprecated")
self.assertEqual(stderr.count('is deprecated'), 1)

def test_deprecated_boolean_option(self):
Expand All @@ -5353,26 +5353,26 @@ def test_deprecated_boolean_option(self):
with captured_stderr() as stderr:
parser.parse_args(['--foo'])
stderr = stderr.getvalue()
self.assertRegex(stderr, "warning: usage of option '--foo' is deprecated")
self.assertRegex(stderr, "warning: option '--foo' is deprecated")
self.assertEqual(stderr.count('is deprecated'), 1)

with captured_stderr() as stderr:
parser.parse_args(['-f'])
stderr = stderr.getvalue()
self.assertRegex(stderr, "warning: usage of option '-f' is deprecated")
self.assertRegex(stderr, "warning: option '-f' is deprecated")
self.assertEqual(stderr.count('is deprecated'), 1)

with captured_stderr() as stderr:
parser.parse_args(['--no-foo'])
stderr = stderr.getvalue()
self.assertRegex(stderr, "warning: usage of option '--no-foo' is deprecated")
self.assertRegex(stderr, "warning: option '--no-foo' is deprecated")
self.assertEqual(stderr.count('is deprecated'), 1)

with captured_stderr() as stderr:
parser.parse_args(['--foo', '--no-foo'])
stderr = stderr.getvalue()
self.assertRegex(stderr, "warning: usage of option '--foo' is deprecated")
self.assertRegex(stderr, "warning: usage of option '--no-foo' is deprecated")
self.assertRegex(stderr, "warning: option '--foo' is deprecated")
self.assertRegex(stderr, "warning: option '--no-foo' is deprecated")
self.assertEqual(stderr.count('is deprecated'), 2)

def test_deprecated_arguments(self):
Expand All @@ -5388,14 +5388,14 @@ def test_deprecated_arguments(self):
with captured_stderr() as stderr:
parser.parse_args(['spam'])
stderr = stderr.getvalue()
self.assertRegex(stderr, "warning: usage of argument 'foo' is deprecated")
self.assertRegex(stderr, "warning: argument 'foo' is deprecated")
self.assertEqual(stderr.count('is deprecated'), 1)

with captured_stderr() as stderr:
parser.parse_args(['spam', 'ham'])
stderr = stderr.getvalue()
self.assertRegex(stderr, "warning: usage of argument 'foo' is deprecated")
self.assertRegex(stderr, "warning: usage of argument 'bar' is deprecated")
self.assertRegex(stderr, "warning: argument 'foo' is deprecated")
self.assertRegex(stderr, "warning: argument 'bar' is deprecated")
self.assertEqual(stderr.count('is deprecated'), 2)

def test_deprecated_varargument(self):
Expand All @@ -5410,13 +5410,13 @@ def test_deprecated_varargument(self):
with captured_stderr() as stderr:
parser.parse_args(['spam'])
stderr = stderr.getvalue()
self.assertRegex(stderr, "warning: usage of argument 'foo' is deprecated")
self.assertRegex(stderr, "warning: argument 'foo' is deprecated")
self.assertEqual(stderr.count('is deprecated'), 1)

with captured_stderr() as stderr:
parser.parse_args(['spam', 'ham'])
stderr = stderr.getvalue()
self.assertRegex(stderr, "warning: usage of argument 'foo' is deprecated")
self.assertRegex(stderr, "warning: argument 'foo' is deprecated")
self.assertEqual(stderr.count('is deprecated'), 1)

def test_deprecated_subparser(self):
Expand All @@ -5433,13 +5433,13 @@ def test_deprecated_subparser(self):
with captured_stderr() as stderr:
parser.parse_args(['foo'])
stderr = stderr.getvalue()
self.assertRegex(stderr, "warning: usage of command 'foo' is deprecated")
self.assertRegex(stderr, "warning: command 'foo' is deprecated")
self.assertEqual(stderr.count('is deprecated'), 1)

with captured_stderr() as stderr:
parser.parse_args(['baz'])
stderr = stderr.getvalue()
self.assertRegex(stderr, "warning: usage of command 'baz' is deprecated")
self.assertRegex(stderr, "warning: command 'baz' is deprecated")
self.assertEqual(stderr.count('is deprecated'), 1)


Expand Down

0 comments on commit 5f72bc6

Please sign in to comment.