diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2023-05-19 16:44:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-19 16:44:43 (GMT) |
commit | 27a7d5e1cd5b937d5f164fce572d442672f53065 (patch) | |
tree | 8368b91bae233ca347ecc50fe108cfd0f60ef830 /Lib/argparse.py | |
parent | ac56a854b418d35ad3838f3072604227dc718fca (diff) | |
download | cpython-27a7d5e1cd5b937d5f164fce572d442672f53065.zip cpython-27a7d5e1cd5b937d5f164fce572d442672f53065.tar.gz cpython-27a7d5e1cd5b937d5f164fce572d442672f53065.tar.bz2 |
gh-92248: Deprecate `type`, `choices`, `metavar` parameters of `argparse.BooleanOptionalAction` (#103678)
Co-authored-by: Kirill <80244920+Eclips4@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r-- | Lib/argparse.py | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py index f5f44ff..543d994 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -883,16 +883,19 @@ class Action(_AttributeHolder): 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=None, - choices=None, + type=_deprecated_default, + choices=_deprecated_default, required=False, help=None, - metavar=None): + metavar=_deprecated_default): _option_strings = [] for option_string in option_strings: @@ -902,6 +905,24 @@ class BooleanOptionalAction(Action): 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 + super().__init__( option_strings=_option_strings, dest=dest, |