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

Guido van Rossum guido at python.org
Thu Aug 14 01:11:46 CEST 2014


On Wed, Aug 13, 2014 at 3:21 PM, Juancarlo Añez <apalala at gmail.com> wrote:

>
>
> On Wed, Aug 13, 2014 at 3:14 PM, Guido van Rossum <guido at python.org>
> wrote:
>
>> I am proposing that we adopt whatever mypy uses here, keeping discussion
>> of the details (mostly) out of the PEP. The goal is to make it possible to
>> add type checking annotations to 3rd party modules (and even to the stdlib)
>> while allowing unaltered execution of the program by the (unmodified)
>> Python 3.5 interpreter.
>
>
> I'll comment later on the core subject.
>
> For now, I think this deserves some thought:
>
> Function annotations are not available in Python 2.7, so promoting
> widespread use of annotations in 3.5 would be promoting code that is
> compatible only with 3.x, when the current situation is that much effort is
> being spent on writing code that works on both 2.7 and 3.4 (most
> libraries?).
>
> Independently of its core merits, this proposal should fail unless
> annotations are added to Python 2.8.
>

Actually, mypy already has a solution. There's a codec (
https://github.com/JukkaL/mypy/tree/master/mypy/codec) that you can use
which transforms Python-2-with-annotations into vanilla Python 2. It's not
an ideal solution, but it can work in cases where you absolutely have to
have state of the art Python 3.5 type checking *and* backwards
compatibility with Python 2.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140813/5ad86b97/attachment.html>


More information about the Python-ideas mailing list