Author serhiy.storchaka
Recipients rhettinger, serhiy.storchaka, sir-sigurd, tim.peters
Date 2019-08-29.17:49:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1567100957.62.0.111143432205.issue37976@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2019-08-29 17:49:17serhiy.storchakasetrecipients: + serhiy.storchaka, tim.peters, rhettinger, sir-sigurd
2019-08-29 17:49:17serhiy.storchakasetmessageid: <1567100957.62.0.111143432205.issue37976@roundup.psfhosted.org>
2019-08-29 17:49:17serhiy.storchakalinkissue37976 messages
2019-08-29 17:49:17serhiy.storchakacreate