class vs type
Colin J. Williams
cjw at sympatico.ca
Fri Oct 19 18:21:25 CEST 2007
Hrvoje Niksic wrote:
> "Colin J. Williams" <cjw at sympatico.ca> writes:
>> In Python Types and Objects, Shalabh Chaturvedi says (in the Python
>> 3.0 documentation - New Style Classes)
>> "The term class is traditionally used to imply an object created by
>> the class statement. However, classes are now synonymous with
>> types. Built-in types are usually not referred to as classes. This
>> book prefers using the term type for both built-in and user created
>> Do we need two different words to describe what is essentially the
>> same thing?
> We don't, not anymore, which is why the author chooses the word "type"
> for both in the last sentence.
In this case, why do we continue to use
the word class to generate a type?
> But, as the author correctly explains, class and type used to not be
> the same thing. Classes were created with 'class', and they were
> fundamentally different from C types created in extension modules.
> All instances of old-style classes are of type 'instance', which is
> why they have the __class__ attribute, so you can find their actual
> class. (Functions like "isinstance" contain hacks to support
> old-style classes.) New-style classes elevate Python-level classes to
> types equal to the built-in ones, which is why the word "type" is now
> sufficient for both.
Doesn't Python 3 provide an opportunity
to move away from discussions about
new_style vs old-style? This an
opportunity to treat old-style as a
historical artefact, not requiring
More information about the Python-list