[Python-ideas] TypeHinting: From variable name to type

David Mertz mertz at gnosis.cx
Sun Oct 21 10:44:05 EDT 2018


On Fri, Oct 19, 2018 at 3:18 AM Thomas Güttler <guettliml at thomas-guettler.de>
wrote:

> Now my idea: Per module and/or per file type hinting from variable name.
> Maybe a magic docstring in the __init__.py file:
> variable-name-mapping:
>   {
>     request: django.http.HttpRequest,
> }
>

In general, I like this idea; but really only on a per-file basis.  A short
header at the top would be easy enough for an IDE or linter to scan.  But
imposing the conventions project-wide feels too broad.

There might, of course, be cases where the same name is used for different
purposes in the same file.  But the tool can alert the developer of that...
and in that one file, she could either remove the header of refactor the
names used, as made sense for that particular code.

This is certainly not something that requires language support.  It can
easily be purely a convention, as long as different IDEs, linters, type
checkers, etc. agree on what the convention is.  Maybe at some point in the
future, if the convention becomes adopted, there might be some help in
having a standard library module, or even minimal language recognition, of
the convention.  But let's work on adopting a convention first.



-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181021/1fbaeb22/attachment.html>


More information about the Python-ideas mailing list