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

Antoine Pitrou solipsis at pitrou.net
Tue Apr 21 15:08:27 CEST 2015


On Tue, 21 Apr 2015 22:47:23 +1000
Steven D'Aprano <steve at pearwood.info> wrote:
> 
> Ironically, type hinting will *reduce* the need for intrusive, 
> anti-duck-testing explicit calls to isinstance() at runtime:

It won't, since as you pointed out yourself, type checks are purely
optional and entirely separate from compilation and runtime evaluation.

> Why bother making that expensive isinstance call every single time the 
> function is called, if the type checker can prove that x is always a 
> float?

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.

(and because of the former property, type hints can be entirely wrong -
for example incomplete, or too strict, or too lax - without anyone
noticing as long as they are self-consistent, since runtime behaviour is
unaffected by them)

Regards

Antoine.




More information about the Python-Dev mailing list