[Python-ideas] Using rightarrow "->" for typing annotation of functions

Vaibhav Karve vaibhavskarve at gmail.com
Wed Apr 24 17:29:06 EDT 2019

(Note: This idea is about a particular static typecheking (typing?)
annotation syntax).
The idea is that currently the use of the "->" (right arrow) is restricted
to only function definition annotation. Can we extent it to declaration of
type for functions even outside their definitions?

Currently we write:
    f: Callable[[int, Dict[str, int]], str]  # declaring the type of some
fake function

This would be much cleaner if we could write:
    f: int -> Dict[str, int] -> str   # One of the possibilities

or even:
    f: int, Dict[str, int] -> str      # Another possibility

I have no idea how this will affect the existing syntax (and if this will
have any bad repercussions/notational misuse). I just thought it would be
nicer to:
a) Not have to spell out Callable
b) Not have to use all those square brackets
c) Have the same notation work for both the function annotation as well as
for declaring the type.

This is my first time posting an idea to python-ideas. So apologies if i am
not following some conventions that i might not be aware of.
Vaibhav Karve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190424/ea3a211c/attachment-0001.html>

More information about the Python-ideas mailing list