[Python-Dev] type vs. class terminology
Guido van Rossum
guido at python.org
Mon Nov 26 16:52:41 CET 2012
Hm. None of the distinctions brought up so far really hit true with me
(though they all are part of the picture). For example, I think the
distinction between type(x) and x.__class__ is rarely significant -- I
bet that if anyone were to rely on this they'd first have to change a
lot of code that used one or the other without much thinking about the
difference. So we might as well consider these equivalent.
Part of the distinction is probably just in historical usage -- many
idioms hark back to when there *was* a difference.
If I had to invent an artificial difference, I'd say that I use "type"
when talking about the type as a fairly abstract concept, such as the
type of a variable (which may be required to be in a given set, for
example), whereas I'll say "class" when I'm interested in the class as
an object, or its definition (through a class statement). So, if I'm
going to ask for the name, the phrase "the name of the class" rolls
easier off my tongue than "the name of the type". OTOH if I'm going to
just assert set membership, I might slightly prefer "x's type must be
int or str".
It's clear that we ought to at least cross-link the two glossary
entries and point out that they are the same concept (type(x) vs.
x.__class__) notwithstanding. I don't think it's important to try and
eradicate the word type from our conversation or our docs -- so no
sweeping global changes, please. However, if you come across a use of
either one in the docs that seems odd given modern usage, feel free to
clean it up, perhaps after checking with someone else to make sure
your intuition matches that of others.
--Guido van Rossum (python.org/~guido)
More information about the Python-Dev