[Python-ideas] Argparse argument deprecation

Ned Batchelder ned at nedbatchelder.com
Wed Aug 9 06:59:18 EDT 2017


OK, then on a more pragmatic note: why is it easier to write a callback
than to write a simple if statement after the parsing?  Generating help
is complex, and a common task that is closely tied to the syntax of the
options, so it makes sense for argparse to do it.  Deprecation is
neither complex, common, nor closely tied to the syntax of the options.

Another note about the proposal: calling it "deprecated" seems odd,
since the proposal is really just a general-purpose callback.  argparse
isn't generating the warning, your callback function would be doing it. 
Why name it "deprecated"?  How is this different than the "action"
keyword argument that argparse already provides?

--Ned.


On 8/9/17 5:54 AM, Michel Desmoulin wrote:
> Argparse is not just about parsing, it's about providing convenient
> tooling associated with parsing.
>
> Otherwise you would not have automatically generated a "usage" message
> or a "--help" command.
>
> Following your definition, those are not parsing. But there are here,
> because we all end up coding them anyway.
>
> Le 09/08/2017 à 11:50, Ned Batchelder a écrit :
>> On 8/9/17 3:56 AM, Tarek Ziadé wrote:
>>> Hey,
>>>
>>> I don't think there's any helper to deprecate an argument in argparse
>>>
>>> Let's say you have a --foo option in your CLI and want to deprecate it
>>> in the next release before you completely remove it later.
>>>
>>> My first though on how to do this by adding a new "deprecated" option to
>>> https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument
>>>
>>> "deprecated" would be a callable that is called after the argument has
>>> been parsed by argparse, 
>>> so the developer can decide if they want to issue a deprecation warning,
>>> use the parsed value or override it etc.
>> I don't see why this is something that argparse has to do.  The
>> semantics of options is handled by the rest of the program.  Why would
>> the parser be issuing these warnings?  Let argparse parse the options,
>> then let other code deal with what they *mean*.
>>
>> --Ned.
>>
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/



More information about the Python-ideas mailing list