[Python-ideas] Argparse argument deprecation
Michel Desmoulin
desmoulinmichel at gmail.com
Wed Aug 9 05:23:45 EDT 2017
+1, but I would make "deprecated" either a warning, an exception or a
callable.
This way to create a simple deprecation, you just provide
DeprecationWarning('This will be gone in the next release'), or
ValueError('This has been removed in 2.X, use "stuff instead"') if you
decide it's gone for good. But if you need a custom behavior, you pass
in a callable.
Le 09/08/2017 à 09:56, Tarek Ziadé a écrit :
> 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
>
More information about the Python-ideas
mailing list