This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author brett.cannon
Recipients brett.cannon, quabla
Date 2016-02-20.20:10:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1455999027.22.0.0786229390613.issue26394@psf.upfronthosting.co.za>
In-reply-to
Content
To paraphrase Michael, he wants a way to tell argparse that an argument has to be supplied either from the command-line or some other mechanism (e.g., envvar, config file, etc.), but that if the value cannot be found in either situation, argparse fails saying the value is missing. This is different from a default value and making something optional as argparse has no way to signal that a default value isn't available, forcing the user to do the actual check externally to argparse itself. All of this stems from the fact that argparse's default argument stuff happens prior to parsing sys.argv and determining what is missing.

What this probably requires is a new keyword-only argument like `fallback` which is a callable which is only called if an accompanying value isn't found from sys.argv and which can raise some specific exception to signal that the fallback value couldn't be determined on top of missing from sys.argv.
History
Date User Action Args
2016-02-20 20:10:27brett.cannonsetrecipients: + brett.cannon, quabla
2016-02-20 20:10:27brett.cannonsetmessageid: <1455999027.22.0.0786229390613.issue26394@psf.upfronthosting.co.za>
2016-02-20 20:10:27brett.cannonlinkissue26394 messages
2016-02-20 20:10:26brett.cannoncreate