[Python-ideas] Proposal: Use mypy syntax for function annotations
Terry Reedy
tjreedy at udel.edu
Thu Aug 21 08:03:46 CEST 2014
On 8/20/2014 9:42 PM, Stephen J. Turnbull wrote:
> Terry Reedy writes:
>
> > If the annotation for a library are in a separate skeleton file
>
> You mean stub file, right? (Stub is the term used so far in this
> thread.)
Then yes, that I what i mean ;-).
> To develop Terry's idea a bit more explicitly, ISTM that during early
> development, you use Python 3 with annotations in file. Then when you
> need to test Python 2, you use a tool (as yet to be developed) which
> generates a Python file that has had all annotations stripped, and a
> stub file[1]. Throw away the stub file, test the Python file, and
> return to development.
An alternative is to develop code and stub separately. There are people
(not core developers) already working on stub files for the stdlib and
other libraries. In fact there are multiple groups using different
syntaxes. Presumably some will join forces if there is a blessed,
standard, syntax. There are no plans to add annotations to the stdlib
code itself.
Even if one does not add annotations to one own code, which many
projects, especially smaller ones, will not, there will be the
possibility of having calls into the stdlib and other annotated or
stubbed libraries statically checked on 3.5 (or later). One will be
able to at least partially benefit without writing annotations oneself.
> For distribution (to *both* Python 3 and Python 2 users) you ignore
> the original annotated code and distribute the generated Python file
> and the stubs file. Probably there would be a tool for combining the
> Python and stub files back into an annotated Python file.
>
> The two tools (stripper and annotator) can be very accurate (although
> the annotator may not produce precisely the style desired by users,
> the tools probably can be designed so that the re-annotated file
> accurately reflects the style used by the authors).
I imagine both tools will emerge.
> Is the implied workflow really so burdensome? Especially to
> downstream?
>
> Note that Terry works on IDLE,
I have been watching this thread precisely from that viewpoint.
> so it seems likely that at least one
> Python IDE would support this workflow very well. :-)
Part this summer's Idle GSOC project was developing a framework to run
3rd party code checkers on code in an Idle editor from the editor. I
just need to review and possibly revise the code Saimadhav wrote and
decide among the alternatives tried. Acesss to existing pyflakes,
pylint, or anything else, once installed (easy now with pip), will soon
be possible.
Anything in the stdlib, rather than at PyPI or wherever, would likely
get even more direct support. For instance, one can check syntax
without running the edit buffer, and I believe that just imports and
runs tokenize.tokenize. I can imagine doing something similar with
stripper, splitter, and joiner functions. (This might be in an
extension module so the feature can to disabled, as might be appropriate
for a beginner class.)
--
Terry Jan Reedy
More information about the Python-ideas
mailing list