[Python-Dev] Type hints -- a mediocre programmer's reaction

Paul Sokolovsky pmiscml at gmail.com
Tue Apr 21 15:50:42 CEST 2015


Hello,

On Tue, 21 Apr 2015 15:08:27 +0200
Antoine Pitrou <solipsis at pitrou.net> wrote:

[]

> Because the user might not run the type checker, obviously. To quote
> you: """When we say that type checking is optional, we mean it."""
> 
> You can't at the same time point out that type checking has no
> power or control over runtime behaviour, and then claim that type
> checking makes runtime behaviour (for example, ability to accept or
> reject certain types) saner. It is a trivial contradiction.

I suspected there's either short-sightedness, or just a word play for
for a purpose of word play.

Type annotation are NOT introduced for the purpose of static type
checking. The current PEP just gives an example of their usage for
static type checking as an example backed by the immediate availability
of a tool which does that, MyPy.

But granted, static type checking is the most boring of possible usages
for type annotation. Runtime type checking (run as via "make test", not
as "production") is much more interesting to catch errors. The tooling
for that is yet to be written though.

Even more interesting usage is to allow ahead-of-time, and thus
unbloated, optimization. There're bunch of JITters and AOTters for
Python language, each of which uses own syntax (via decorators, etc.)
to annotate functions. Having language-specified type annotations
allows for portable syntax for such optimized code.

Granted, the most juicy usages described above won't be available in
CPython out of the box. But there should be that motto: "CPython is the
most boring of all Pythons". Don't block the language if you're stuck
with an unimaginative implementation, there's much more to Python than
that.


-- 
Best regards,
 Paul                          mailto:pmiscml at gmail.com


More information about the Python-Dev mailing list