Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Definitive documentation on newstyle classes? (WAS: Picklingand inheritance are making me hurt)

Reply
Thread Tools

Re: Definitive documentation on newstyle classes? (WAS: Picklingand inheritance are making me hurt)

 
 
Brian van den Broek
Guest
Posts: n/a
 
      02-06-2005
Daniel Bickett said unto the world upon 2005-02-05 19:46:
> I was reading the "Pickling and inheritance are making me hurt"
> thread, and the latest suggestion (as of this posting) was to do with
> the __setstate__ and __getstate__ methods. They caught my attention
> because I hadn't encountered them before, and it reminded me that in
> the past I've never been able to very good, definitive documentation
> on newstyle classes. Googling for it gives little python tutorials on
> various sites, and even searching this newsgroup returns very specific
> questions, as a rule.
>
> Alas, the question: Does there exist a page that enumerates all of the
> features of the newstyle classes, and explains what they all do? If
> so, can anyone provide me with such a link?
>
> Thanks


Hi Daniel,

it doesn't yet answer the "definitive" part, but
<http://www.python.org/moin/NewClassVsClassicClass> is worth a look.

Best,

Brian vdB
 
Reply With Quote
 
 
 
 
Colin J. Williams
Guest
Posts: n/a
 
      02-08-2005
Brian van den Broek wrote:
> Daniel Bickett said unto the world upon 2005-02-05 19:46:
>
>> I was reading the "Pickling and inheritance are making me hurt"
>> thread, and the latest suggestion (as of this posting) was to do with
>> the __setstate__ and __getstate__ methods. They caught my attention
>> because I hadn't encountered them before, and it reminded me that in
>> the past I've never been able to very good, definitive documentation
>> on newstyle classes. Googling for it gives little python tutorials on
>> various sites, and even searching this newsgroup returns very specific
>> questions, as a rule.
>>
>> Alas, the question: Does there exist a page that enumerates all of the
>> features of the newstyle classes, and explains what they all do? If
>> so, can anyone provide me with such a link?
>>
>> Thanks

>
>
> Hi Daniel,
>
> it doesn't yet answer the "definitive" part, but
> <http://www.python.org/moin/NewClassVsClassicClass> is worth a look.
>
> Best,
>
> Brian vdB


Yes, that's the best I've come across. But a clearer overall view, tied
in to the Language Reference, would be very helpful.

It would be good to have a clear exposition of the pros and cons of
__new__ usage.

Colin W.

 
Reply With Quote
 
 
 
 
Michele Simionato
Guest
Posts: n/a
 
      02-09-2005
> It would be good to have a clear exposition of the pros and cons of
> __new__ usage.


It is there mostly because __init__ would not work on immutable types.
OTOH, you probably do not want to use __new__ on mutable types
(once I was caught by this trap, google for "overriding list.__new__"
if you are interested).

Michele Simionato

 
Reply With Quote
 
Colin J. Williams
Guest
Posts: n/a
 
      02-09-2005
Michele Simionato wrote:
>>It would be good to have a clear exposition of the pros and cons of
>>__new__ usage.

>
>
> It is there mostly because __init__ would not work on immutable types.
> OTOH, you probably do not want to use __new__ on mutable types
> (once I was caught by this trap, google for "overriding list.__new__"
> if you are interested).
>
> Michele Simionato
>

Thanks. The use of __new__ for immutable classes is described in:
http://www.python.org/2.2.3/descrintro.html

This distinction hadn't registered with me before.

The Martelli bible doesn't bring this out.

It seems to me that __new__ should probably be deprecated for mutable
classes.

Colin W.
 
Reply With Quote
 
Michele Simionato
Guest
Posts: n/a
 
      02-09-2005
Colin:
> It seems to me that __new__ should probably be deprecated for mutable
> classes.


Certainly not! It is useful for mutable classes too. One just must be
careful.

Michele Simionato

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Definitive max flash/DRAM for a 2621 non-XM J Cisco 1 02-10-2006 08:45 PM
newstyle classes and __getattribute__ Stefan Sonnenberg-Carstens Python 5 10-28-2005 10:01 PM
Definitive documentation on newstyle classes? (WAS: Pickling andinheritance are making me hurt) Daniel Bickett Python 2 02-06-2005 01:39 AM
Newstyle Types Confounding! Pete Shinners Python 0 06-23-2004 06:39 AM
Why exception is not newstyle class? kyo Python 1 01-05-2004 01:13 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57