Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-92248: Deprecatetype
,choices
,metavar
parameters ofargparse.BooleanOptionalAction
#103678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
5524230
gh-92248: Deprecate `type`, `chocies`, `metavar` parameters of `argpa…
sobolevn5df2d40
Update Misc/NEWS.d/next/Library/2023-04-22-12-30-10.gh-issue-92248.Nc…
sobolevne32aa16
Merge branch 'main' into issue-92248
arhadthedev808826b
Apply suggestions from code review
sobolevnf95263f
Merge branch 'main' into issue-92248
hugovk6ab98ac
Merge branch 'main' into issue-92248
hugovkFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletionsDoc/whatsnew/3.12.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
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 |
---|---|---|
@@ -883,16 +883,19 @@ def __call__(self, parser, namespace, values, option_string=None): | ||
raise NotImplementedError(_('.__call__() not defined')) | ||
# FIXME: remove together with `BooleanOptionalAction` deprecated arguments. | ||
_deprecated_default = object() | ||
class BooleanOptionalAction(Action): | ||
def __init__(self, | ||
option_strings, | ||
dest, | ||
default=None, | ||
type=_deprecated_default, | ||
choices=_deprecated_default, | ||
required=False, | ||
help=None, | ||
metavar=_deprecated_default): | ||
_option_strings = [] | ||
for option_string in option_strings: | ||
@@ -902,6 +905,24 @@ def __init__(self, | ||
option_string = '--no-' + option_string[2:] | ||
_option_strings.append(option_string) | ||
# We need `_deprecated` special value to ban explicit arguments that | ||
# match default value. Like: | ||
# parser.add_argument('-f', action=BooleanOptionalAction, type=int) | ||
for field_name in ('type', 'choices', 'metavar'): | ||
if locals()[field_name] is not _deprecated_default: | ||
warnings._deprecated( | ||
field_name, | ||
"{name!r} is deprecated as of Python 3.12 and will be " | ||
"removed in Python {remove}.", | ||
remove=(3, 14)) | ||
if type is _deprecated_default: | ||
type = None | ||
if choices is _deprecated_default: | ||
choices = None | ||
if metavar is _deprecated_default: | ||
metavar = None | ||
hugovk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
super().__init__( | ||
option_strings=_option_strings, | ||
dest=dest, | ||
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
2 changes: 2 additions & 0 deletionsMisc/NEWS.d/next/Library/2023-04-22-12-30-10.gh-issue-92248.NcVTKR.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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Deprecate ``type``, ``choices``, and ``metavar`` parameters of | ||
``argparse.BooleanOptionalAction``. |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.