[Python-Dev] Iterable String Redux (aka String ABC)

Armin Ronacher armin.ronacher at active-4.com
Fri May 30 16:48:41 CEST 2008


Greg Ewing <greg.ewing <at> canterbury.ac.nz> writes:

> Well, I'm skeptical about the whole ABC thing in the
> first place -- it all seems very unpythonic to me.
I think it's very pythonic and the very best solution to interfaces *and*
duck typing.  Not only does it extend duck-typing in a very, very cool way
but also does it provide a very cool way to get custom sets or lists going
with few extra work.  Subclassing builtins was always very painful in the
past and many used the User* objects which however often broke because some
code did something like isinstance(x, (tuple, list)).  Of course one could
argue that instance checking is the root of all evil but there are
situations where you have to do instance checking.  And ABCs are the
perfect solution for that as they combine duck-typing and instance
checking.

In my oppinion ABCs are the best feature of 2.6 and 3.0.

> But another way of thinking about it is that we
> already have an ABC of sorts for strings, and it's
> called basestring. It might be better to enhance
> that with whatever's considered missing than
> introducing another one.
basestring is not subclassable for example.  Also it requires subclassing
which ABCs do not.

Regards,
Armin



More information about the Python-Dev mailing list