Serhiy Storchaka <[email protected]> added the comment:
Agree. This is an improvement of UX.
The initial code was added in 8572b4fedf7e6ee4cd350680d53cd0a21574b083.
Other option is to check ahead if the argument is an iterable.
if (!item->ob_type->tp_iter && !PySequence_Check(item)) {
// Raise specific TypeError
}
(We can introduce a special API for this, PyIterable_Check, if there are other
use cases).
This is a part of larger issue. When we parse arguments using Argument Clinic,
in some cases we can check the type ahead and report what argument (by name or
positional number) of what function has wrong type. But in other cases we just
call the converting function, and the detailed information about argument and
function is lost. For example:
>>> ''.encode(123)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: encode() argument 'encoding' must be str, not int
>>> ''.encode('\0')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: embedded null character
----------
nosy: +tim.peters
type: -> enhancement
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue37976>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com