Re: modifying __new__ of list subclass

2006-08-15 Thread Ken Schutte
Steven Bethard wrote: > So even though your __new__ method returns the object you want, the > __init__ method is clearing out all the items you've added and then > re-adding them as it normally would. To prove this to yourself, take a > look at what happens when we override __init__:: > Okay,

Re: modifying __new__ of list subclass

2006-08-15 Thread Steven Bethard
Ken Schutte wrote: > Steven Bethard wrote: >> >> The __new__ method is for immutable types. So things like str and int >> do their initialization in __new__. But for regular mutable types, >> you should do your initialization in __init__:: > > I see... So, is there a use for __new__ in mutable

Re: modifying __new__ of list subclass

2006-08-15 Thread Alex Martelli
Ken Schutte <[EMAIL PROTECTED]> wrote: > Steven Bethard wrote: > > > > The __new__ method is for immutable types. So things like str and int > > do their initialization in __new__. But for regular mutable types, you > > should do your initialization in __init__:: > > I see... So, is there a us

Re: modifying __new__ of list subclass

2006-08-15 Thread Ken Schutte
Steven Bethard wrote: > > The __new__ method is for immutable types. So things like str and int > do their initialization in __new__. But for regular mutable types, you > should do your initialization in __init__:: > I see... So, is there a use for __new__ in mutable types? From my list-d

Re: modifying __new__ of list subclass

2006-08-14 Thread Steven Bethard
Ken Schutte wrote: > I want an int-derived class that is initilized to one greater than what > it's constructor is given: > > class myint(int): > def __new__(cls, intIn): > newint = int(intIn+1) > return int.__new__(cls, newint) Or simply: class myint(int): def __new__(cls, int_i