[Python-de] name2type mapping

Thomas Güttler guettliml at thomas-guettler.de
Fr Okt 26 03:53:22 EDT 2018


Hallo,

ich habe mal eine Idee veröffentlicht, die mir schon lange
vorschwebt:

    https://github.com/guettli/python-name2type-mapping/

Feedback is willkommen.


------------------------------


Python name2type mapping

In October 2018 on the mailing list python-ideas some developers encouraged me, that the idea of a name2type mapping 
would be usefull.

Goal:

     Better type-hints in IDEs.

This is not the goal:

     Type-hints which get used during run-time.

Syntax Proposal

The name2type mapping is defined in the docstring of a Python file.

The general syntax is "name2type:" followed by a comma sperated list of variable names. Then ":", then the type hint.

Examples:

"""
name2type: my_int, my_number, ....: int
name2type: request*: django.http.HttpRequest
""""

If the docstring is in a file called __init__.py, then the type hints get specified for all files below this directory 
(recursively).
Misc

     The name2type mapping is just a fall-back. First the IDE does the usual type detection and if no type could be 
found, then name2type mapping gets used. Except explicitly switched off. But this switch is not part of the spec.




-- 
Thomas Guettler http://www.thomas-guettler.de/
I am looking for feedback: https://github.com/guettli/programming-guidelines


Mehr Informationen über die Mailingliste python-de