Author paul.j3
Recipients mhughes, paul.j3, rhettinger, xtreak
Date 2020-07-10.16:41:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1594399306.03.0.354942507588.issue41255@roundup.psfhosted.org>
In-reply-to
Content
The docs could change 

"catch errors manually"

to

"catch ArgumentError manually"

But while 'argparse.ArgumentError' is imported, it is not documented. We have to study the code to learn when it is raised.  

Its class def:

    def __init__(self, argument, message):

shows it's tied to a specific 'argument', an Action object.  Most commonly it is produced by reraising a ValueError, TypeError or ArgumentTypeError during the check_values step.

Unrecognized arguments, and missing required arguments errors aren't produced while processing an argument, but rather while checking  things after parsing.  So they can't raise an ArgumentError, and aren't handled by this new parameter.

I found a old issue that discusses this https://bugs.python.org/issue9938,  https://github.com/python/cpython/pull/15362

There wasn't much discussion about the scope of this change, or about the documentation wording.  My only comment was in 2013, https://bugs.python.org/msg192147

Until we iron out the wording I think this patch should be reverted.

While exploring other problems, I thought it would be a good idea of refactor parse_known_args and _parse_known_args.  Specifically I'd move the 'required' testing and self.error() calls out of _parse_known_args, allowing a developer to write their own versions of parse_known_args.  The goal was to make it easier to test for mixes of seen and unseen arguments.  

In light of the current issue, we might want to look into consolidating all (or at least most) of the calls to self.error() in one function.  Until then, the documented idea of modifying the error() method itself is the best user/developer tool, https://docs.python.org/3.10/library/argparse.html#exiting-methods
History
Date User Action Args
2020-07-10 16:41:46paul.j3setrecipients: + paul.j3, rhettinger, xtreak, mhughes
2020-07-10 16:41:46paul.j3setmessageid: <1594399306.03.0.354942507588.issue41255@roundup.psfhosted.org>
2020-07-10 16:41:46paul.j3linkissue41255 messages
2020-07-10 16:41:45paul.j3create