pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/pull/124751/files

="https://github.githubassets.com/assets/primer-primitives-26e89bb5a0c37ae9.css" /> [3.13] gh-80259: Fix conflict between type and default=SUPPRESS in argparse (GH-124519) by miss-islington · Pull Request #124751 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2511,7 +2511,7 @@ def _get_values(self, action, arg_strings):
value = action.const
else:
value = action.default
if isinstance(value, str):
if isinstance(value, str) and value is not SUPPRESS:
value = self._get_value(action, value)
self._check_value(action, value)

Expand Down
20 changes: 13 additions & 7 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1556,18 +1556,24 @@ class TestDefaultSuppress(ParserTestCase):
"""Test actions with suppressed defaults"""

argument_signatures = [
Sig('foo', nargs='?', default=argparse.SUPPRESS),
Sig('bar', nargs='*', default=argparse.SUPPRESS),
Sig('foo', nargs='?', type=int, default=argparse.SUPPRESS),
Sig('bar', nargs='*', type=int, default=argparse.SUPPRESS),
Sig('--baz', action='store_true', default=argparse.SUPPRESS),
Sig('--qux', nargs='?', type=int, default=argparse.SUPPRESS),
Sig('--quux', nargs='*', type=int, default=argparse.SUPPRESS),
]
failures = ['-x']
failures = ['-x', 'a', '1 a']
successes = [
('', NS()),
('a', NS(foo='a')),
('a b', NS(foo='a', bar=['b'])),
('1', NS(foo=1)),
('1 2', NS(foo=1, bar=[2])),
('--baz', NS(baz=True)),
('a --baz', NS(foo='a', baz=True)),
('--baz a b', NS(foo='a', bar=['b'], baz=True)),
('1 --baz', NS(foo=1, baz=True)),
('--baz 1 2', NS(foo=1, bar=[2], baz=True)),
('--qux', NS(qux=None)),
('--qux 1', NS(qux=1)),
('--quux', NS(quux=[])),
('--quux 1 2', NS(quux=[1, 2])),
]


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :mod:`argparse` support of positional arguments with ``nargs='?'``,
``default=argparse.SUPPRESS`` and specified ``type``.
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy