Do we still need to inherit from "object" to create new-style classes?

Discussion in 'Python' started by John Salerno, Jun 21, 2011.

  1. John Salerno

    John Salerno Guest

    I can't quite seem to find the answer to this anywhere. The book I'm
    reading right now was written for Python 3.1 and doesn't use (object),
    so I'm thinking that was just a way to force new-style classes in 2.x
    and is no longer necessary in 3.x. Is that right?

    (The documentation doesn't mention object anymore, but elsewhere on
    the Python website it says the documentation hasn't been updated for
    new-style classes yet, hence my confusion.)

    Thanks.
    John Salerno, Jun 21, 2011
    #1
    1. Advertising

  2. Re: Do we still need to inherit from "object" to create new-styleclasses?

    On Mon, Jun 20, 2011 at 6:26 PM, John Salerno <> wrote:
    > I can't quite seem to find the answer to this anywhere. The book I'm
    > reading right now was written for Python 3.1 and doesn't use (object),
    > so I'm thinking that was just a way to force new-style classes in 2.x
    > and is no longer necessary in 3.x. Is that right?
    >
    > (The documentation doesn't mention object anymore, but elsewhere on
    > the Python website it says the documentation hasn't been updated for
    > new-style classes yet, hence my confusion.)
    >
    > Thanks.


    3.x got rid of old-style classes altogether, so you are correct-
    there's no need to explicitly subclass object.
    Benjamin Kaplan, Jun 21, 2011
    #2
    1. Advertising

  3. John Salerno

    John Salerno Guest

    On Jun 20, 8:33 pm, Benjamin Kaplan <> wrote:
    > On Mon, Jun 20, 2011 at 6:26 PM, John Salerno <> wrote:
    > > I can't quite seem to find the answer to this anywhere. The book I'm
    > > reading right now was written for Python 3.1 and doesn't use (object),
    > > so I'm thinking that was just a way to force new-style classes in 2.x
    > > and is no longer necessary in 3.x. Is that right?

    >
    > > (The documentation doesn't mention object anymore, but elsewhere on
    > > the Python website it says the documentation hasn't been updated for
    > > new-style classes yet, hence my confusion.)

    >
    > > Thanks.

    >
    > 3.x got rid of old-style classes altogether, so you are correct-
    > there's no need to explicitly subclass object.


    Thanks! And apologies for having to start a thread to ask just that! :)
    John Salerno, Jun 21, 2011
    #3
  4. John Salerno

    Terry Reedy Guest

    Re: Do we still need to inherit from "object" to create new-styleclasses?

    On 6/20/2011 9:26 PM, John Salerno wrote:
    > I can't quite seem to find the answer to this anywhere. The book I'm
    > reading right now was written for Python 3.1 and doesn't use (object),
    > so I'm thinking that was just a way to force new-style classes in 2.x
    > and is no longer necessary in 3.x. Is that right?
    >
    > (The documentation doesn't mention object anymore,


    Lib ref 2. builtin functions:
    "object()
    Return a new featureless object. object is a base for all classes. It
    has the methods that are common to all instances of Python classes. This
    function does not accept any arguments.

    Note
    object does not have a __dict__, so you can’t assign arbitrary
    attributes to an instance of the object class.
    "

    > but elsewhere on
    > the Python website it says the documentation hasn't been updated for
    > new-style classes yet, hence my confusion.)


    What page? *It* may need updating ;-).

    The core 3.x docs have been updated by removing all reference to
    old-style classes and the modifier 'new-style'. The concept 'new-style'
    only exists in opposition to 'old-style'. 3.x just has classes, and all
    are subclasses of object.

    --
    Terry Jan Reedy
    Terry Reedy, Jun 21, 2011
    #4
    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. ankit
    Replies:
    1
    Views:
    328
    Alex Martelli
    Dec 22, 2005
  2. Isaac Rodriguez

    Are all classes new-style classes in 2.4+?

    Isaac Rodriguez, Dec 31, 2006, in forum: Python
    Replies:
    4
    Views:
    379
    Steven D'Aprano
    Dec 31, 2006
  3. Kza
    Replies:
    4
    Views:
    411
    Andrew Koenig
    Mar 3, 2006
  4. Quek
    Replies:
    3
    Views:
    323
  5. Ken Varn
    Replies:
    0
    Views:
    428
    Ken Varn
    Apr 26, 2004
Loading...

Share This Page