Distinction between “class” and “type”

Ben Finney ben+python at benfinney.id.au
Fri May 13 01:07:04 EDT 2016


Howdy all,

Ever since Python's much-celebrated Grand Unification of classes and
types, I have used those terms interchangeably: every class is a type,
and every type is a class.

That may be an unwise conflation. With the recent rise of optional type
annotation in Python 3, more people are speaking about the important
distinction between a class and a type.

This recent message from GvR, discussing a relevant PEP, advocates
keeping them separate:

    PEP 484 […] tries to make a clear terminological between classes
    (the things you have at runtime) and types (the things that type
    checkers care about).

    There's a big overlap because most classes are also types -- but not
    the other way around! E.g. Any is a type but not a class (you can
    neither inherit from Any nor instantiate it), and the same is true
    for unions and type variables. […]

    <URL:https://mail.python.org/pipermail/python-ideas/2016-May/040237.html>

As a Bear of Little Brain, this leaves me clueless. What is the
distinction Guido alludes to, and how are Python classes not also types?

And why is this distinction important, and who moved my cheesecake?

-- 
 \        “It is the responsibility of intellectuals to tell the truth |
  `\                    and to expose lies.” —Noam Chomsky, 1967-02-23 |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list