PEP 526 - var annotations and the spirit of python

Bart bc at freeuk.com
Thu Jul 5 06:26:54 EDT 2018


On 05/07/2018 10:59, Steven D'Aprano wrote:

> But it is redundant in *that* example. Your hint is not giving any more
> information that what the reader, or type checker, can already infer.
> 
> These are useful:
> 
>      x: Any = 3  # x can be anything, but is currently an int
> 
>      x: int = None # x can be an int, or None
> 
>      x: Union[int, str] = 'abc'  # x can be either an int, or a
>      # string, not just the string you see here

This is one reason I dropped type hinting from my own developments.

It's a poor, half-baked version of both true static typing, and of true 
type inference.

Look at Haskell for how type inference can be done well (I have to 
admire it even if I don't understand it).

And at numerous other languages that are properly statically typed (Ada 
being one of the most rigorous, while C++ is a nightmare).

-- 
bart


More information about the Python-list mailing list