[Python-ideas] PEP 484 (Type Hints) -- first draft round

Greg greg.ewing at canterbury.ac.nz
Mon Jan 19 01:01:18 CET 2015

On 19/01/2015 8:34 a.m., Guido van Rossum wrote:
> I'm putting a line in the sand: annotations are
> for types

Do you mean *static* types, or types in general?

If they're only for static type checking, this seems a waste of a
facility that evaluates things at run time. Moreover, evaluating
them at run time is actually counterproductive, since it makes
dealing with things like forward references unnecessarily awkward.
It also introduces useless runtime overhead. And they only address
part of the problem, since they only apply to functions and not
other things we might want to specify the type of.

If you've decided that static type checking is important
enough to officially support, how about designing a new language
feature specifically for that?

We could, for example, borrow Haskell's :: symbol:

class Duck:

   num_feathers :: int = 4200

   def quack(volume :: float)

The type expressions following :: would have the form of
Python expressions, but they would not be evaluated.
Introspecting on them at runtime could be supported, but
you would get an AST instead of a value.


More information about the Python-ideas mailing list