[Python-ideas] Trial balloon: adding variable type declarations in support of PEP 484

Guido van Rossum guido at python.org
Wed Aug 3 12:15:05 EDT 2016


On Wed, Aug 3, 2016 at 8:31 AM, Joao S. O. Bueno <jsbueno at python.org.br> wrote:
> I may have missed that on the message deluge so far - but would the
> type annotations
> be available at runtime, like parameter annotations live in "__annotations__"?

Actually we've hardly touched on that yet. For classes I think it
would be nice to make these available. For locals I think we should
not evaluate the type at all, otherwise the cost of using a variable
declaration would be too high.

> An __annotations__ dict straight in the class itself? I thinkt hat is
> the obvious thing - although I did not see it in the above messages.
> (A s I said, I may have missed its mention)
>
> That is rather important because then, beyond enabling static code
> analysis it is easy to have third party frameworks that enforce typing
> in runtime.

Although, frankly, that's not something that PEP 484 particularly
cares about. Runtime type checking has very different requirements --
would you really want to check that a List[int] contains only ints if
the list has a million items?

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-ideas mailing list