A better way of making subsclassing of built-in types stick for attributes?

telesphore4 at gmail.com telesphore4 at gmail.com
Wed May 17 15:07:32 CEST 2006


Ben Finney wrote:
> "telesphore4 at gmail.com" <telesphore4 at gmail.com> writes:
> > Of course, whenever you then set mystr = 'a string'
> ... you're instantiating a 'str' object, since that's what the syntax
> you use will do.
> > you loose the extra goodies that I have attached in the
> > subclass.
> Because you haven't created an object of that subclass.


> The syntax used to make the object assigned to 'foo' is just a
> shortcut for the syntax used to assign to 'bar'. If you want to
> instantiate anything else, you need to use that explicit syntax, such
> as for the object assigned to 'baz'.
> If you're hoping that "subclass" means "modify the behaviour of the
> original class", you're mistaken. It makes a *new* class that has
> behaviour *inherited from* the original class.

Nah. I was hoping that I hadn't muffed the implementation and there was
a more Pythonic way of doing what I wanted.

Sounds like I've gotten things mostly right from the get go. which is
reassuring for a newbie. using __set__ is the correct way to hide the
vectoring to the __new__ assignment... no further shortcuts.

thanks again

More information about the Python-list mailing list