[issue20039] Missing documentation for argparse.ArgumentTypeError
New submission from Arnaut Billings: There is no documentation for argparse.ArgumentTypeError: http://docs.python.org/3/library/unittest.html 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... ---------- assignee: docs@python components: Documentation messages: 206723 nosy: arnaut-billings, docs@python priority: normal severity: normal status: open title: Missing documentation for argparse.ArgumentTypeError versions: Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20039> _______________________________________
paul j3 added the comment: 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). ---------- nosy: +paul.j3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20039> _______________________________________
Arnaut Billings added the comment: 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.) ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20039> _______________________________________
Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- nosy: +bethard type: -> enhancement _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue20039> _______________________________________
paul j3 <ajipanca@gmail.com> added the comment: A related closed request: https://bugs.python.org/issue30220 that wants to test ValueError for non-generic message, instead of using ArgumentTypeError. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue20039> _______________________________________
Nicholas Chammas <nicholas.chammas@gmail.com> added the comment: Just a note that I also went looking for the docs for argparse.ArgumentTypeError after coming across it in this (highly viewed) post: https://stackoverflow.com/a/14117511/877069 ---------- nosy: +nchammas _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue20039> _______________________________________
Change by Rahul Kumaresan <kayrahul@gmail.com>: ---------- nosy: +rahul-kumi _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue20039> _______________________________________
participants (5)
-
Arnaut Billings
-
Ezio Melotti
-
Nicholas Chammas
-
paul j3
-
Rahul Kumaresan