[Python-Dev] Type hints -- a mediocre programmer's reaction
James Edwards
jheiv at jheiv.com
Wed Apr 22 00:23:28 CEST 2015
Cory Benfield <cory at lukasa.co.uk>
"python-dev at python.org" <python-dev at python.org>
On Tue, Apr 21, 2015 at 8:47 AM, Cory Benfield <cory at lukasa.co.uk> wrote:
> I'm talking from the position of being a library author, where supporting
> versions of Python lower than 3.5 will be a reality for at least 5 more years.
> I will not be able to inline my type hints, so they'll have to go in
> stub files, and now we've got the same problem: type hints can go out
> of step just as easily as documentation can.
I imagine authors interested in both type hinting and backwards compatibility
could write their code using the 3.0+ annotation syntax, while using the various
backwards compatibility packages and schemes, then "split" the source file
using some inevitably-available tool to generate both annotation-free source and
associated stub files.
The author maintains (directly, at least) files on a 1-to-1 ratio -- the fact
that they are split prior to distribution is transparent (much like generating
documentation from source / comments).
Running such a preprocessing step may not be ideal, but it is certainly an
option that the motivated package author would seem to have, if they were so
inclined.
--
FWIW, my gut reaction was the same as many on the list (the syntax can get
verbose and negatively impact readability), but I think we're only seeing one
side of the eventual coin, looking at individual, sometimes specifically
chosen examples.
In theory, if this "takes off", IDEs could do a lot to help reduce the burden.
Maybe they provide a "read-only" view of functions/methods where annotations are
hidden until you put the caret inside the block, at which point the hints are
revealed. Maybe even inside the block they're hidden, until you attempt to edit
the arguments.
Maybe they're just always gathered up by the IDE and accessible through some
panel widget.
Some of these approaches may sound helpful to some, others not so much, but the
point is that there are a lot of creative ways that IDEs *could* help ease the
transition, if type hinting becomes of significant interest to the community.
More information about the Python-Dev
mailing list