[Python-3000] Use cases for type annotations? (WAS: Type parameterization)

Steven Bethard steven.bethard at gmail.com
Sat May 20 06:42:49 CEST 2006


On 5/19/06, Collin Winter <collinw at gmail.com> wrote:
> As a quick data point, I showed around your "dict[str, str|int]"
> example to some friends, all of whom have done a decent amount of
> coding in Python. I gave them some background, including that this was
> an example of type parameterization. To quote one fellow, a PhD
> student in CS at Edinburgh: "So, uh, 'dict[str, int|str]' is supposed
> to represent... uh... I give in, what the hell is that supposed to
> denote?"
>
> I know the plural of "anecdote" isn't "data"; maybe c.l.p should be
> polled on some of these things?

I think c.l.py is definitely not the right place to go right now.
It'll just dissolve into a syntax debate without touching on any of
the real issues.

Which brings me to my comment about the current discussion.  Can't we
drop the syntax discussion for a while and have someone motivate it
with some use-cases first?  Sure, I can figure out what ``dict[str,
str|int]`` means, but I still have no idea what you'd gain by
declaring a parameter to have such a type.  Should it add checks every
time __getitem__ or __setitem__ is called?

I think that if we can figure out what people would actually use type
annotations for, I think it'll be much clearer what exactly needs
syntactic support.  At the moment, I can see a few simple uses that
would only make things painful -- e.g. parameters getting declared as
ints when any number type would work -- or that seem too
computationally inefficient -- e.g. dict[str, str] would presumably
have to add type-checks at every __getitem__ or __setitem__ call.

STeVe

P.S.  I did look at
http://svn.python.org/projects/sandbox/trunk/typecheck, but couldn't
find any use-case examples.
-- 
Grammar am for people who can't think for myself.
        --- Bucky Katt, Get Fuzzy


More information about the Python-3000 mailing list