[Python-ideas] Proposal: Use mypy syntax for function annotations
Andrey Vlasovskikh
andrey.vlasovskikh at gmail.com
Thu Aug 14 13:36:26 CEST 2014
On Thu, Aug 14, 2014 at 2:28 PM, Manuel Cerón <ceronman at gmail.com> wrote:
> 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?
We use something quite similar to TypeScript's repository of
annotations in PyCharm. Here is our external annotations proposal and
stubs for some stdlib modules
(https://github.com/JetBrains/python-skeletons) that uses a custom
type syntax in docstrings due to lack of a better standard, see
README. We state in our proposal that we would like the standard to
emerge. The idea being discussed here about using Mypy's type system
is not new to us. As I've mentioned in the original thread, we have
discussed it with Jukka Lehtosalo, the author of Mypy. Some initial
ideas are listed here (https://github.com/pytypes/pytypes).
--
Andrey Vlasovskikh
Web: http://pirx.ru/
More information about the Python-ideas
mailing list