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 arnaut-billings, docs@python, paul.j3
Date 2013-12-21.18:37:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1387651064.98.0.804345628122.issue20039@psf.upfronthosting.co.za>
In-reply-to
Content
In argparse.py the status of ArgumentTypeError is ambiguous.

ArgumentError is listed as a public class, ArgumentTypeError is not.  It also says 'All other classes in this module are considered implementation details.'

ArgumentTypeError is a subclass of Exception (with no added functionality).

ArgumentTypeError is raised only once, in the FileType class (which is both a scripting convenience and example of a custom type).  As you note it is also used in the documentation example.  There is also one such example in test_argparse.py.

It is caught once, where it is converted into an ArgumentError.  It is handled much like a ValueError or TypeError - except that its message is passed through unchanged.  

In http://bugs.python.org/issue13824 I use it several times in the FileContext class for just this reason.  

In fact ArgumentTypeError could be documented as a footnote to the `type` block, saying to the effect: 'An ArgumentTypeError may be raised (instead of a ValueError or TypeError) to produce a custom error message.'

Normally an ArgumentTypeError is not passed back to the user code, consistent with the claim that it is not public.

--------------

Along the same line, should ArgumentError be documented better?  Currently it is just mentioned at the end, as a replacement for an optparse error class.

As best I can tell, the user code will only see an ArgumentError if the ArgumentParser.error method is customized.  Otherwise that error is caught and converted into a system exit.  Maybe the `error` paragraph in the documentation should get a sentence about ArgumentError.

In test_argparse.py, ArgumentError is used extensively (with a custom error method).
History
Date User Action Args
2013-12-21 18:37:45paul.j3setrecipients: + paul.j3, docs@python, arnaut-billings
2013-12-21 18:37:44paul.j3setmessageid: <1387651064.98.0.804345628122.issue20039@psf.upfronthosting.co.za>
2013-12-21 18:37:44paul.j3linkissue20039 messages
2013-12-21 18:37:43paul.j3create