[Python-ideas] Proposal: Use mypy syntax for function annotations

Manuel Cerón ceronman at gmail.com
Thu Aug 14 12:28:26 CEST 2014


On Thu, Aug 14, 2014 at 1:24 AM, Guido van Rossum <guido at python.org> wrote:

> On Wed, Aug 13, 2014 at 3:26 PM, Manuel Cerón <ceronman at gmail.com> wrote:
>
>> The type checking algorithm might evolve over the time, but by including
>> typing.py in the stdlib, the syntax for annotations would be almost frozen
>> and that will be a limitation. In other projects such as TypeScript (
>> http://www.typescriptlang.org/), that the syntax usually evolves
>> alongside the algorithms.
>>
>
> What kind of evolution did TypeScript experience?
>

There is a nice summary of breaking changes here:
https://typescript.codeplex.com/wikipage?title=Known%20breaking%20changes%20between%200.8%20and%200.9

Most of these are in the way that the type checking engine works, but there
are some syntax changes. While the basic types have remained stable, some
special things have not. For example: generics, optional and default
arguments, interfaces.

I think it'd be valuable to learn from TypeScript as much as possible, it's
the only project that I know that It's trying to bring static type analysis
to a widely used dynamically typed language.

One interesting feature of TypeScript is that it allows you to annotate
existing code without modifying it, by using external definition files. In
the JavaScript world, many people have contributed TypeScript annotation
files for popular JS libraries (http://definitelytyped.org/).

I think this is possible in Python as well doing something like this:

@annotate('math.ciel')
def ciel(x: float) -> int:
    pass

I think this should be the way to go for annotating the stdlib. It has the
advantage that if the type syntax changes, it's possible to provide new
type annotations without changing the libraries at all, and even supporting
older versions. In this way the code and type annotations can evolve
separately.

Does mypy support something like this?

Manuel.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140814/a41bfbfc/attachment.html>


More information about the Python-ideas mailing list