
Typed Python: new Mypy release - 1st1
http://mypy-lang.blogspot.com/2016/05/mypy-04-released.html
======
ericfrederich
HIGHLY recommend watching this video

[https://vimeo.com/74354480](https://vimeo.com/74354480) linked to from:
[http://games.greggman.com/game/dynamic-typing-static-
typing/](http://games.greggman.com/game/dynamic-typing-static-typing/) linked
to from:
[https://news.ycombinator.com/item?id=10933524](https://news.ycombinator.com/item?id=10933524)

~~~
m_mueller
Thank you, that's really one of the best talks I've seen lately.

------
gregwebs
MyPy works surprisingly well once you add this in a few places: # type: ignore

The (now documented) --silence-imports option will remove the most frequent
use for ignoring types though.

This project is very similar to TypeScript or Flow and I have found it
provides a similar huge boost in reliability.

------
azaras
I don't try it yet but it remember me Groovy type system. It is a great
feature.

No type checker was one of the bigger flaws in Python.

When in Groovy, I use type checker in public functions and APIs. It is a good
communication tool.

In my opinion, Python is better than Groovy. This feature still make it
better.

~~~
networked
I've used Python a lot more than Groovy but one thing I find myself missing
from Python and other scripting languages since I discovered Groovy is the
ability for a standalone script to retrieve its dependencies on startup. What
this means is that if you put

    
    
      @Grab(group='foo', module='bar', version='1.0.0')
    

at the top of randomscript.groovy you will have bar available to import by the
time the script starts.

~~~
azaras
You could use:

import pip

pip.main(['install', 'bar'])

~~~
networked
It's not this simple. That code will only work if you are root or in a
virtualenv — and having to create a virtualenv manually contradicts the idea
of a self-contained, standalone script that manages dependencies on its own.
To install bar as a non-root user you will have to do

    
    
      import pip
      pip.main(['install', '--user', 'bar'])
    

which throws an error, e.g., if bar is already installed, meaning you will
have to wrap the calls to pip.main() in a "try" block and differentiate
between the types of errors they throw.

The above already makes it noticably less convenient for a script to manage
its own dependencies. The killing blow, however, comes form the fact that pip
won't let you install multiple versions of the same package in parallel: the
most recently installed version overwrites the previous one. This means that a
script that relies on a per-user package store can only be safe if it checks
the version of every package it uses and replaces it if needed each time it is
run. This can a take a long time and is error prone (what if your Internet
connection goes down?) but the alternative is simply to deal with the
brittleness.

I can see this being solved for Python but the solution will probably involve
automatically creating and caching per-script virtualenvs. For now, though,
something like PyInstaller (i.e., binaries) remains more practical if you want
to distribute standalone Python scripts.

~~~
azaras
I am sorry I made a mistake. You are right. Thanks for the explanation.

~~~
networked
No worries!

------
gshulegaard
Why has no one mentioned the Python 3.5 has type hinting?

[https://docs.python.org/3/library/typing.html](https://docs.python.org/3/library/typing.html)

The PEP 484 proposal:

[https://www.python.org/dev/peps/pep-0484/](https://www.python.org/dev/peps/pep-0484/)

------
shubhjain
I am looking forward to the feature of strict optional types checking which
will not treat None as a inhabited value of any type.

------
tanlermin
Can the type information be consumed by a compiler like nuitka to produce fast
binaries?

~~~
mzs
You might be more interested in Cython.

~~~
tanlermin
Cython is uglier and without type inference.

I wish we could just use mypy when we feel like making our code faster :/

------
symlinkk
is there such thing as a typed interpreted language? I mean one with a REPL,
not Java.

~~~
Xophmeister
Presumably, ultimately, all languages are typed in some way. Otherwise, how
would the interpreter (or whatever execution environment is relevant) deduce
what binary data was what?

I think the question you mean -- which I'm also interested in the answer to --
is: How can a _dynamically_ typed language be statically type checked?
Presumably Hindley-Milner style inference doesn't/can't work. Do static
analysers such as Mypy therefore trace the execution of the code until it
finds something that conflicts? Are there cases where this approach won't
work, either technically or practically?

~~~
boomlinde
Forth is what I would consider an untyped language. It deals with numbers on a
stack in a way that it is totally up to the programmer to decide what they
represent. One number may be a IEEE 754 number, an unsigned integer, a signed
integer, the address of a string, a fixed-point number, a couple of ASCII
characters etc.

~~~
RodgerTheGreat
Same deal with most forms of assembly language- the values you work with are
just numbers, and the operations to which you apply them are what give them a
particular meaning at a particular point in time- addresses, offsets,
integers, booleans, etc. It's possible to argue that such languages are
"unityped" rather than "untyped", but I think to do so is to produce such a
loose interpretation of "types" as to be uninteresting.

------
sametmax
Still no support for await / async :( Guido worked on asyncio and works on
this tool, I was expecting more love.

------
B1FF_PSUVM
They should also implement a generics/template system.

(Barking at the wrong tree intensifies.)

~~~
masklinn
> They should also implement a generics/template system.

What are you talking about? MyPy has supported generics since before the 0.1
release:
[https://github.com/python/mypy/blob/v0.1.0/docs/source/gener...](https://github.com/python/mypy/blob/v0.1.0/docs/source/generics.rst)

