Why are so many built-in types inheritable?
Antoon Pardon
apardon at forel.vub.ac.be
Thu Mar 30 09:31:46 EST 2006
Op 2006-03-28, Georg Brandl schreef <g.brandl-nospam at gmx.net>:
> Fabiano Sidler wrote:
>> I really wanted to learn the reason for this, nothing else! ;)
>
> I suspect performance reasons. Can't give you details but function
> is used so often that it deserves special treatment.
I would find this a bit odd. I think integers, tuples and lists
are used just as often if not more and they aren't treated special.
I for one would gladly treat some performance for the ability
to subclass slices.
class islice(slice):
...
doesn't work
And if I just write
class islice:
def __init__(self, start, stop, step):
self.start = start
self.stop = stop
self.step = step
then the following doesn't work:
lst = range(20)
sl = islice(2,6,None)
lst[sl]
So much for ducktyping.
--
Antoon Pardon
More information about the Python-list
mailing list