Message260572
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. |
|
Date |
User |
Action |
Args |
2016-02-20 20:10:27 | brett.cannon | set | recipients:
+ brett.cannon, quabla |
2016-02-20 20:10:27 | brett.cannon | set | messageid: <1455999027.22.0.0786229390613.issue26394@psf.upfronthosting.co.za> |
2016-02-20 20:10:27 | brett.cannon | link | issue26394 messages |
2016-02-20 20:10:26 | brett.cannon | create | |
|