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 paul.j3
Recipients Thermi, joker, paul.j3, rhettinger
Date 2021-07-28.19:47:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1627501655.76.0.00294733419455.issue44748@roundup.psfhosted.org>
In-reply-to
Content
I've explored something similar in 

https://bugs.python.org/issue11588
Add "necessarily inclusive" groups to argparse

There is a local variable in parser._parse_known_args

    seen_non_default_actions

that's a set of the actions that have been seen.  It is used for testing for required actions, and for mutually_exclusive groups.  But making it available to users without altering user API code is awkward.

My latest idea was to add it as an attribute to the parser, or (conditionally) as attribute of the namespace

https://bugs.python.org/issue11588#msg265734

I've also thought about tweaking the interface between

parser._parse_known_args
parser.parse_known_args

to do of more of the error checking in the caller, and give the user more opportunity to do their checks. This variable would be part of _parse_known_args output.

 
Usually though when testing like this comes up on SO, I suggest leaving the defaults as None, and then just using a 

     if args.foobar is None:
          # not seen

Defaults are written to the namespace at the start of parsing, and seen arguments overwrite those values (with an added type 'eval' step of remaining defaults at the end).


Keep in mind, though, that the use of subparsers could complicate any of these tweaks.

In reading my posts on https://bugs.python.org/issue26394, I remembered the IPython uses argparse (subclassed) with config.  I believe it uses config inputs (default and user) to define the arguments for the parser.


So unless someone comes up with a really clever idea, this is bigger request than it first impressions suggest.
History
Date User Action Args
2021-07-28 19:47:35paul.j3setrecipients: + paul.j3, rhettinger, Thermi, joker
2021-07-28 19:47:35paul.j3setmessageid: <1627501655.76.0.00294733419455.issue44748@roundup.psfhosted.org>
2021-07-28 19:47:35paul.j3linkissue44748 messages
2021-07-28 19:47:35paul.j3create