[Python-3000] [Python-Dev] Iterable String Redux (aka String ABC)
oren at hishome.net
Sun Jun 1 11:42:00 CEST 2008
On Tue, May 27, 2008 at 12:42:48PM -0700, Guido van Rossum wrote:
> On Tue, May 27, 2008 at 12:32 PM, Armin Ronacher
> <armin.ronacher at active-4.com> wrote:
> > A problem comes up as soon as user defined strings (such as UserString) is
> > passed to the function. In my opinion a good solution would be a "String"
> > ABC one could test against.
> I'm not against this, but so far I've not been able to come up with a
> good set of methods to endow the String ABC with. Another problem is
> that not everybody draws the line in the same place -- how should
> instances of bytes, bytearray, array.array, memoryview (buffer in 2.6)
> be treated?
> --Guido van Rossum (home page: http://www.python.org/~guido/)
The issue goes beyond iterability. If a user defined string such as
UserString that is not derived from one of the "true" builtin string
types is passed to a builtin function that expects a string it will be
rejected. PyArgs_ParseTuple discriminates against such user defined
If a String ABC is implemented it could be used as a signal that the
object is not just convertable to a string (virtually all objects are)
but IS a string and its __str__ should be used during builtin function
More information about the Python-3000