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 rhettinger
Recipients Thermi, joker, paul.j3, rhettinger, terry.reedy, wodny85
Date 2021-09-03.01:29:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1630632547.86.0.172695537041.issue44748@roundup.psfhosted.org>
In-reply-to
Content
> I want the order of priority to fall back to the defaults,
> if no value is specified in the config file. And if an argument
> is passed via argv, then that value should take precedence 
> over what is set in the config file.

from collections import ChainMap
from argparse import ArgumentParser

parser = ArgumentParser()
missing = object()
for arg in 'abcde':
    parser.add_argument(f'-{arg}', default=missing)
system_defaults = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}
config_file =     {'a': 6,         'c': 7,         'e': 8}
command_line = vars(parser.parse_args('-a 8 -b 9'.split()))
command_line = {k: v for k, v in command_line.items() if v is not missing}
combined = ChainMap(command_line, config_file, system_defaults)
print(dict(combined))

> This is in the first message in this issue.

The feature request is clear.  What problem you're trying to solve isn't clear.  What you're looking for is likely some permutation of the above code or setting a argument default to a value in the ChainMap.  I think you're ignoring that we already have ways to set default values to anything that is needed and we already have ways to tell is an argument was not encountered (but not both at the same time).

[Paul J3]
> So unless someone comes up with a really clever idea, 
> this is bigger request than it first impressions suggest.

I recommend rejecting this feature request.  The module is not obliged to be all things to all people.  Most variations of the problem already have a solution.  We should leave it at that.  Extending the namespace with extra boolean arguments would just open a can of worms that would make most users worse off, likely breaking any code that expects the namespace to contain exactly what it already contains.
History
Date User Action Args
2021-09-03 01:29:07rhettingersetrecipients: + rhettinger, terry.reedy, paul.j3, Thermi, joker, wodny85
2021-09-03 01:29:07rhettingersetmessageid: <1630632547.86.0.172695537041.issue44748@roundup.psfhosted.org>
2021-09-03 01:29:07rhettingerlinkissue44748 messages
2021-09-03 01:29:07rhettingercreate