homepage

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.

classification
Title: Improve error reporting for the argument parsing C API
Type: enhancement Stage: test needed
Components: C API, Interpreter Core Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Ankur.Ankan, benjamin.peterson, cito, iritkatriel, larry, mishok13, rhettinger, ronaldoussoren
Priority: low Keywords:

Created on 2008年07月14日 12:53 by cito, last changed 2022年04月11日 14:56 by admin.

Messages (9)
msg69651 - (view) Author: Christoph Zwerschke (cito) * Date: 2008年07月14日 12:53
When you sort a list with list.sort() or sorted(list), and set the
reverse parameter to None, then you get the following misleading error
message:
 TypeError: an integer is required
I would expect a more proper error message for the reverse parameter,
such as "reverse must be a boolean", and maybe reverse=None also
accepted as default value, i.e. False.
msg69653 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008年07月14日 13:30
Well, booleans technically are integers.
msg69657 - (view) Author: Christoph Zwerschke (cito) * Date: 2008年07月14日 15:19
The problem is not only that the error message "TypeError: an integer is
required" has "integer" instead of "boolean", but it does not mention
the attribute name "reverse", i.e. it does not even say *where* the
integer is required. I firmly believe error messages should not only be
technically correct, but also precise, meaningful and helpful for the user.
msg69658 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008年07月14日 15:22
Patches are welcome.
msg69659 - (view) Author: Christoph Zwerschke (cito) * Date: 2008年07月14日 18:22
The unspecific error message is thrown by the vgetargskeywords()
function, so changing this behavior would be a larger, more difficult
and general issue (similar to #1283289). We could go another path and
require an object for 'reverse' instead of an integer in the format
parameter, and then do our own checks and error messages on 'reverse'.
This looks reasonable if we want to change the behavior anyway, so that
reverse=None is accepted (cmp=None and key=None are also accepted), or
even an implicit bool(reverse) is used (but this could hide possible
errors). If we want to keep the behavior and only fix the error message,
then a more general fix of vgetargskeywords() seems to be the proper
solution.
msg69662 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2008年07月14日 21:44
I think this is closer to a language wide change and should probably be 
addressed for 2.7 and 3.1. It would be great to change the C argument 
parsing API to make its error messages more specific.
For Py2.6, I think things are fine as it stands. This isn't a bug 
(tests pass, it matches results from previous pythons, etc) 
Reclassifying as a feature request for improved error reports for the 
argument parsing API.
msg69669 - (view) Author: Christoph Zwerschke (cito) * Date: 2008年07月14日 23:40
Agree. Seems to be a more general weakness of the argument parsing of
builtin functions and methods, that calls for a general solution instead
of a local patch. Luckily there are not so many cases where the errors
are misleading, since the builtin functions have very few and mostly
positioned parameters, so the problem is not as bad as it seems. There
may be only very few cases, like the example above, where the errors are
really too unspecific or misleading.
msg191584 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013年06月21日 14:34
See also #18269.
msg407295 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021年11月29日 16:50
Reproduced in 3.11:
>>> sorted([1,2,3], reverse=None)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object cannot be interpreted as an integer
History
Date User Action Args
2022年04月11日 14:56:36adminsetgithub: 47604
2021年11月29日 16:50:41iritkatrielsetnosy: + iritkatriel

messages: + msg407295
versions: + Python 3.11, - Python 3.3
2020年06月25日 09:41:11vstinnersetcomponents: + C API
2013年06月21日 14:34:58ronaldoussorensetnosy: + ronaldoussoren
messages: + msg191584
2013年06月21日 08:36:39pitrousetnosy: + larry
2013年06月19日 18:53:56Ankur.Ankansetnosy: + Ankur.Ankan
2012年02月21日 02:34:42eric.araujosettitle: Improve error reporting for the argument parsing API -> Improve error reporting for the argument parsing C API
versions: + Python 3.3, - Python 2.7, Python 3.2
2009年05月16日 20:35:13ajaksu2setstage: test needed
versions: + Python 3.2, - Python 3.1
2008年07月14日 23:40:25citosetmessages: + msg69669
2008年07月14日 21:44:22rhettingersettype: behavior -> enhancement
title: sort(reverse=None) prints misleading error message -> Improve error reporting for the argument parsing API
messages: + msg69662
nosy: + rhettinger
versions: + Python 3.1, Python 2.7, - Python 2.6, Python 2.5, Python 2.4
2008年07月14日 18:22:10citosetmessages: + msg69659
2008年07月14日 17:10:45mishok13setnosy: + mishok13
2008年07月14日 15:22:53benjamin.petersonsetstatus: closed -> open
priority: low
resolution: wont fix ->
messages: + msg69658
2008年07月14日 15:19:24citosetmessages: + msg69657
2008年07月14日 13:40:09benjamin.petersonsetstatus: open -> closed
resolution: wont fix
2008年07月14日 13:30:56benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg69653
2008年07月14日 12:53:23citocreate

AltStyle によって変換されたページ (->オリジナル) /