Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108581

Re: Distinction between “class” and “type”

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Distinction between “class” and “type”
Date 2016-05-13 15:23 +1000
Message-ID <mailman.624.1463117015.32212.python-list@python.org> (permalink)
References <85eg96eebr.fsf@benfinney.id.au> <CAPTjJmoGuAs8bFRFEW2Qyg9c9a5ntSFbew=_o24V9g8HUYBd1w@mail.gmail.com>

Show all headers | View raw


On Fri, May 13, 2016 at 3:07 PM, Ben Finney <ben+python@benfinney.id.au> wrote:
> 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?

The difference, as I understand it, is that types are abstract and
classes are concrete. The problem is that 'type' is an actual concrete
thing, so terminology is messy; but the examples are pretty clear -
you can't instantiate Any the way you can instantiate str or int.
There's a similar difference with ABCs like Sequence - you can't
construct a Sequence, but you can document that you expect to be
passed one.

Maybe the solution is to have a new word for "things a type checker
looks for"... except that that really does want to be, uhh, "types".
Or maybe the solution is to have a new word for "things you can
construct with the class keyword"... except that that that's "types"
too, because they're all subclasses of 'type'.

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

Because it wouldn't make sense if you asked who moved your bacon.

Mmm. Bacon. With cheesecake for afters.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Distinction between “class” and “type” Chris Angelico <rosuav@gmail.com> - 2016-05-13 15:23 +1000

csiph-web