[Python-Dev] type vs. class terminology

Xavier Morel python-dev at masklinn.net
Mon Nov 26 08:50:52 CET 2012


On 2012-11-26, at 07:54 , Nick Coghlan wrote:

> On Mon, Nov 26, 2012 at 3:01 PM, Chris Jerdonek <chris.jerdonek at gmail.com>wrote:
> 
>> I would like to know when we should use "class" in the Python 3
>> documentation, and when we should use "type."  Are these terms
>> synonymous in Python 3, and do we have a preference for which to use
>> and when?
>> 
>> I'm sure this has been discussed before.  But if this terminology
>> issue has already been resolved, the resolution doesn't seem to be
>> reflected in the docs.  For example, the glossary entries for type and
>> class don't reference each other.
>> 
> 
> The historical distinction between "builtin types" and "user-defined
> classes" predates new-style classes (which unified the type system) and
> Python 3 (which eliminated the "instance" type that was provided to
> preserve the legacy user-defined class semantics in Python 2). The glossary
> unfortunately still reflects this distinction, which no longer exists in
> Python 3.
> 
> A slightly more useful distinction would be if type was used consistently
> to refer to type(x), while class was used to refer to x.__class__, since
> they can and do differ in the case of proxy types (like weakref.proxy).
> However, it's probably too late for that kind of fine distinction - in
> reality, the two terms are now used pretty much interchangeably.

There's an other possible usage which is between `type` subclasses and
`type` instances (`type` essentially becomes a synonym for `metaclass`),
I've seen that kind of usage at least once in the docs:
http://docs.python.org/2/c-api/object.html#PyObject_IsInstance

> If cls is a type object rather than a class object, PyObject_IsInstance()
> returns 1 if inst is of type cls.


More information about the Python-Dev mailing list