[Python-ideas] Argparse argument deprecation

Tarek Ziadé tarek at ziade.org
Wed Aug 9 03:56:20 EDT 2017


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.

Another interesting approach suggest by Doug Hellman, which I like as
much, is a set of higher level options that
provide a deprecation workflow for arguments, see

https://github.com/openstack/oslo.config/blob/master/oslo_config/cfg.py#L441

What do you think?

Cheers
Tarek

-- 

Tarek Ziadé | coding: https://ziade.org | running: https://foule.es |
twitter: @tarek_ziade


More information about the Python-ideas mailing list