Issue3354
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) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
Date: 2013-06-21 14:34 | |
See also #18269. |
|||
| msg407295 - (view) | Author: Irit Katriel (iritkatriel) * ![]() |
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:36 | admin | set | github: 47604 |
| 2021-11-29 16:50:41 | iritkatriel | set | nosy:
+ iritkatriel messages:
+ msg407295 |
| 2020-06-25 09:41:11 | vstinner | set | components: + C API |
| 2013-06-21 14:34:58 | ronaldoussoren | set | nosy:
+ ronaldoussoren messages: + msg191584 |
| 2013-06-21 08:36:39 | pitrou | set | nosy:
+ larry |
| 2013-06-19 18:53:56 | Ankur.Ankan | set | nosy:
+ Ankur.Ankan |
| 2012-02-21 02:34:42 | eric.araujo | set | title: 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:13 | ajaksu2 | set | stage: test needed versions: + Python 3.2, - Python 3.1 |
| 2008-07-14 23:40:25 | cito | set | messages: + msg69669 |
| 2008-07-14 21:44:22 | rhettinger | set | type: 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:10 | cito | set | messages: + msg69659 |
| 2008-07-14 17:10:45 | mishok13 | set | nosy: + mishok13 |
| 2008-07-14 15:22:53 | benjamin.peterson | set | status: closed -> open priority: low resolution: wont fix -> messages: + msg69658 |
| 2008-07-14 15:19:24 | cito | set | messages: + msg69657 |
| 2008-07-14 13:40:09 | benjamin.peterson | set | status: open -> closed resolution: wont fix |
| 2008-07-14 13:30:56 | benjamin.peterson | set | nosy:
+ benjamin.peterson messages: + msg69653 |
| 2008-07-14 12:53:23 | cito | create | |
