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.

Title: Missing documentation for argparse.ArgumentTypeError
Type: enhancement Stage: patch review
Components: Documentation Versions: Python 3.3
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: arnaut-billings, bethard, docs@python, nchammas, paul.j3, rahul-kumi, ukarroum
Priority: normal Keywords: patch

Created on 2013-12-21 10:40 by arnaut-billings, last changed 2022-04-11 14:57 by admin.

Pull Requests
URL Status Linked Edit
PR 31125 open ukarroum, 2022-02-04 07:08
Messages (5)
msg206723 - (view) Author: Arnaut Billings (arnaut-billings) Date: 2013-12-21 10:40
There is no documentation for argparse.ArgumentTypeError:

Though it does appear in an example and its usage is simple enough to decipher what it means, it would none the less look more professional if there was formal documentation for it. Not only on what it is, but when it should actually be used, etc...
msg206768 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2013-12-21 18:37
In 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

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 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, ArgumentError is used extensively (with a custom error method).
msg206783 - (view) Author: Arnaut Billings (arnaut-billings) Date: 2013-12-21 21:23
It seems what you're saying is that the ArgumentTypeError class should not be public, but being able to raise is should be public. If that's the case, I think it would be more clear to have an argparse.raiseArgumentTypeError method and document when it should be used.

If such classes are meant to be private, why not prepend their names with an underscore and remove them from the __all__ list? (I thought a leading underscore meant that a module level variable was private to that module.)
msg327986 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2018-10-18 16:41
A related closed request:

that wants to test ValueError for non-generic message, instead of using ArgumentTypeError.
msg363839 - (view) Author: Nicholas Chammas (nchammas) * Date: 2020-03-10 19:01
Just a note that I also went looking for the docs for argparse.ArgumentTypeError after coming across it in this (highly viewed) post:
Date User Action Args
2022-04-11 14:57:55adminsetgithub: 64238
2022-02-04 07:08:15ukarroumsetkeywords: + patch
nosy: + ukarroum

pull_requests: + pull_request29304
stage: patch review
2020-03-11 19:08:43rahul-kumisetnosy: + rahul-kumi
2020-03-10 19:01:08nchammassetnosy: + nchammas
messages: + msg363839
2018-10-18 16:41:31paul.j3setmessages: + msg327986
2014-02-15 15:11:38ezio.melottisetnosy: + bethard
type: enhancement
2013-12-21 21:23:43arnaut-billingssetmessages: + msg206783
2013-12-21 18:37:44paul.j3setnosy: + paul.j3
messages: + msg206768
2013-12-21 10:40:25arnaut-billingscreate