[Python-3000] Use cases for type annotations?

Guido van Rossum guido at python.org
Sat May 20 16:41:55 CEST 2006


On 5/19/06, Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl> wrote:
> "Steven Bethard" <steven.bethard at gmail.com> writes:
>
> > 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?

Read my blogs (over a year old) on the topic. I believe Collin
references them regularly in these threads.

> > 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?
>
> Indeed. And if passes through a variable with a declared type multiple
> times in a loop, would it accumulate multiple checking layers?
>
> If "mapping" is substituted for "dict", is it wrapped while preserving
> the class? How?
>
> IMHO any type checking which would require wrapping in a checking
> layer makes no sense; besides the risk of accumulating checking
> layers, it doesn't detect type violation at the time of the check
> anyway.

We're way ahead of you two. The annotations are meant as
documentation, for tools like pychecker, and (perhaps, with suitable
decorators) for things like adaptation. While some participants in
this thread have written systems that actually (dynamically) verify
that arguments passed in match the type specs, the intent is *not*
that that will be a standard feature. Nor is it intended to cause
optimized bytecode to be written.

It's all in the blogs.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list