Inherit from array
Scott David Daniels
scott.daniels at acm.org
Thu Apr 27 16:47:10 EDT 2006
bruno at modulix wrote:
> TG wrote:
>> Hmm ... I'm definitely not a python wizard, but it seems to be quite a
>> special case that breaks the rules ...
>
> Yes and no. The primary use case for __new__ was to allow subclassing of
> immutable types. array.array is not immutable, but it's still a special
> case, in that it enforce type-based restrictions.
The alternative is to either:
1) Allow arrays that have no type.
or 2) Allow arrays that change type.
Neither is a tasty alternative. __new__ sets the stuff that
must be invariant (and for an array, that is the element type),
and __init__ does any further initialization (initialization
should be re-runnable). In the case of array, filling the array
with data seems a great use of __init__.
--
-Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list