[Python-Dev] inheriting basic types more efficiently

Dennis Heuer dh at triple-media.com
Wed Apr 26 18:28:36 CEST 2006


Have never seen such an answer before. Please excuse if I read it
wrong. The method would just return the new values, for shure. That is
what it shall do. The interpreter calls that method for receiving the
new (to be used) values to pass them on to the real target (the called
attribute). The method is a kind of filter to be used intermediately.

Dennis

On Wed, 26 Apr 2006 17:35:22 +0200
python-dev-bounces at python.org wrote:

> The results of your email command are provided below. Attached is your
> original message.
> 
> 
> - Unprocessed:
>     quite now:
>     The new-style classes support the inheritance of basic types, like int,
>     long, etc. Inheriting them is nice but not always efficient because one
>     can not *control* the inherited methods but only overwrite them. For
>     example, I want to implement a bitarray type. Because the long type is
>     unlimited and implemented as an integer array (as far as I know), it
>     seems to be a good choice for basing a bitarray type on it. Boolean
>     arithmetics on long integers should work quite fast, I expect. However,
>     the bitarray class should accept different values than the long type
>     accepts, like "101010". This is not only true for initialization but
>     also for comparisons, etc.:
>     if x < "101010": print True.
>     Here now the trouble appears. There seems to be no way to catch an
>     input value before it reaches the attribute, to parse and convert it
>     into the appropriate integer, and to send this integer to the attribute
>     instead. One actually has to overwrite all the inherited methods to
>     call the validation method from inside each of them individually. This
>     renders the inheritance of the long type useless. One could just write
>     a new class instead. This is not optimal.
>     Please think about implementing a method that catches all input values.
> 
> - Ignored:
>     This method would just return the new values.
>     
>     Thanks,
>     Dennis
> 
> - Done.
> 
> 


More information about the Python-Dev mailing list