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

Georg Brandl g.brandl at gmx.net
Sat May 31 13:36:29 CEST 2008


Steven D'Aprano schrieb:

>> 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 
> 
> "Always" very painful?
> 
> class ListWithClear(list):
>     def clear(self):
>         self[:] = self.__class__()
> 
> Not so very painful to me. Maybe I just have more pain-tolerance than 
> some people.

Sure, nobody said that adding another method is a problem.

But overriding methods like __getitem__() and having them used in other
methods that derive from it (like get()) is impossible without resorting
to UserDict, which in turn doesn't inherit from dict.

ABCs unify these possibilities.

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.



More information about the Python-Dev mailing list