Re: Distinction between “class” and “type”

Rustom Mody rustompmody at gmail.com
Fri May 13 01:21:31 EDT 2016


On Friday, May 13, 2016 at 10:37:34 AM UTC+5:30, Ben Finney wrote:
> 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?

I cannot speak for Guido.
However there is a well-known confusion here, most recently spelt out in
Bob Harper's epochal book:
http://www.cs.cmu.edu/~rwh/pfpl.html

If types are compile time things then they are part of the *syntax* of the language
If types are runtime things they are some kind of tags attached to objects *at runtime*

When a language like python with a clear historical orientation towards the second
starts embracing the first, it is natural that people start getting confused --
which I suspect includes Guido.



More information about the Python-list mailing list