[Python-ideas] Proposal: Use mypy syntax for function annotations
Guido van Rossum
guido at python.org
Mon Aug 25 05:29:08 CEST 2014
On Fri, Aug 22, 2014 at 7:30 AM, Bob Ippolito <bob at redivi.com> wrote:
>
>
> On Friday, August 22, 2014, Skip Montanaro <skip at pobox.com> wrote:
>
>> There's been a lot to read in this and related threads over the past nine
>> days. (According to Gmail. It qualitatively seems much longer to me.) I
>> think I've followed along reasonably well. Forgive me if I missed the
>> answers to these questions. The proposal on the table is to adopt MyPy's
>> type annotations for Python 3.mumble. I presume MyPy already supports them.
>>
>> 1. Can MyPy be used today as a standalone static type checker for Python
>> 3.x code without actually compiling anything? That is, can I just sprinkle
>> type annotations into my code and run a front-end pass of MyPy much the
>> same way I'd run pylint, vulture, flake8, or other lint-ish program?
>>
>
> Yes. mypy -S performs checking without execution.
>
> 2. Assuming the answer to #1 is "yes," if you start sprinkling type
>> annotations into your code and running "mypy *.py", will it tell you when
>> it needs a missing type annotation to more fully check things, or will it
>> silently process code without annotations and not let you know that it's
>> not really checking much?
>>
>
> No. It happily and silently accepts dynamic code with no annotations. It
> can't do much for you with that code, but it doesn't complain.
>
However, mypy has a flag --html-report which generates a marked-up source
code listing that shows which regions of the code have or haven't been
checked, using similar color-coding as coverage.py.
> 3. Will we get into a phase like the early days of "const" in ANSI C where
>> addition of "const" in one location in your existing code base forced you
>> into a never-ending iterations of adding const all over the place? I forget
>> what that was called ("const propagation"?), but I recall that it generally
>> wasn't a fun activity.
>>
>
> Nope.
>
The Python interpreter won't force you. Of course you can still play this
game (e.g. by insisting that no red zones should exist in the
above-mentioned source listing) but that's no different from insisting on
zero lint warnings -- it is a choice a developer (usually a team) makes,
not something the software enforces.
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140824/5e3ee032/attachment.html>
More information about the Python-ideas
mailing list