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

Discussion in 'Python' started by Brian van den Broek, Feb 6, 2005.

  1. 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
     
    Brian van den Broek, Feb 6, 2005
    #1
    1. Advertising

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

    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.
     
    Colin J. Williams, Feb 8, 2005
    #2
    1. Advertising

  3. Re: Definitive documentation on newstyle classes? (WAS: Pickling and inheritance are making me hurt)

    > 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
     
    Michele Simionato, Feb 9, 2005
    #3
  4. Re: Definitive documentation on newstyle classes? (WAS: Picklingand inheritance are making me hurt)

    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.
     
    Colin J. Williams, Feb 9, 2005
    #4
  5. Re: Definitive documentation on newstyle classes? (WAS: Pickling and inheritance are making me hurt)

    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
     
    Michele Simionato, Feb 9, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kyo
    Replies:
    1
    Views:
    249
    Jp Calderone
    Jan 5, 2004
  2. Pete Shinners

    Newstyle Types Confounding!

    Pete Shinners, Jun 23, 2004, in forum: Python
    Replies:
    0
    Views:
    272
    Pete Shinners
    Jun 23, 2004
  3. Kirk Strauser

    Pickling and inheritance are making me hurt

    Kirk Strauser, Feb 4, 2005, in forum: Python
    Replies:
    2
    Views:
    298
    Tim Peters
    Feb 6, 2005
  4. Daniel Bickett
    Replies:
    2
    Views:
    311
    Daniel Bickett
    Feb 6, 2005
  5. Stefan Sonnenberg-Carstens

    newstyle classes and __getattribute__

    Stefan Sonnenberg-Carstens, Oct 28, 2005, in forum: Python
    Replies:
    5
    Views:
    317
    Stefan Sonnenberg-Carstens
    Oct 28, 2005
Loading...

Share This Page