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

J

John Salerno

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.
 
B

Benjamin Kaplan

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.
 
J

John Salerno

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! :)
 
T

Terry Reedy

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top