Note that there are some explanatory texts on larger screens.

plurals
  1. POTools for static type checking in Python
    text
    copied!<p>I'm working with a large existing Python codebase and would like to start adding in type annotations so I can get some level of static checking. I'm imagining something like <a href="http://www.erlang.org/doc/reference_manual/typespec.html" rel="noreferrer">Erlang</a>, <a href="http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.51.4406" rel="noreferrer">Strongtalk</a>, or <a href="http://docs.racket-lang.org/ts-guide/more.html#%28part._.Type_.Annotation_and_.Binding_.Forms%29" rel="noreferrer">Typed Scheme/Racket</a>.</p> <p>I've seen quick-and-dirty decorators that insert dynamic checks based on function parameter and return type annotations, but I'm looking for something that is more robust and that performs checks at compile-time.</p> <p>What tools are available right now for this kind of thing? I'm familiar with compilers and type checking and am definitely willing to improve an incomplete tool if it has a good foundation.</p> <p>(Note: I'm not interested in a discussion of the pros/cons of static typing.)</p> <p><strong>EDIT</strong>: An example:</p> <pre><code>def put(d, k, v): d[k] = v </code></pre> <p>I'd like to be able to annotate the <code>put</code> function as having type <code>put&lt;K,V&gt;(dict&lt;K,V&gt;, K, V) -&gt; None</code>.</p> <p><strong>UPDATE</strong>: The new <a href="https://www.python.org/dev/peps/pep-0484/" rel="noreferrer">PEP 484</a> (Sep 2014) defines a standard for static typing and type annotations in Python 3.5+. There's a type-checking tool called <a href="http://mypy-lang.org/" rel="noreferrer">mypy</a> that is compatible with PEP 484.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload