Brett Cannon added the comment:

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.

----------
nosy: +brett.cannon
stage:  -> test needed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26394>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to