Why no list heritable type?
Mike Meyer
mwm at mired.org
Fri Dec 17 18:47:09 EST 2004
Jeff Shannon <jeff at ccvcorp.com> writes:
> Mike Meyer wrote:
>>Jeff Shannon <jeff at ccvcorp.com> writes:
>>>Additionally, as I understand it UserList and UserDict are implemented
>>>entirely in Python, which means that there can be significant
>>>performance differences as well.
>>
>>Actually, UserList and UserDict are just wrappers around the builtin
>>types. So the performance hit is one Python function call - pretty
>>much neglible. But new code should still subclass the builtins.
>
> Ah. I suppose that makes sense, now that the builtins are
> subclassable. Originally, they had to be implemented in Python in
> order to make them subclassable, but now the type/class unification
> has changed all that...
Go take a look at UserList. It's a wrapper around the builtin list,
not a descendant of the builtin list. Most of the methosd look like:
def name(self, args): self.data.name(args)
The exceptions tend to be tweaking the exact behavior based on the
argument type(s).
<mike
--
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list
mailing list