<div dir="ltr"><div>Thanks for posting. I agree that Callable is ugly (even hideous :-), but when we introduced type annotations in PEP 484, we didn't want to introduce new syntax. The existing syntax (using -> in function headings) was supported since Python 3.0.</div><div><br></div><div>Since then we've introduced other new syntax (in particular PEP 526) so we could indeed try adding something better for Callable.</div><div><br></div><div>I think we should probably at least have parentheses around the arguments, so you'd write</div><div><br></div><div>f: (int) -> str</div><div>g: (int, str) -> float<br></div><div><br></div><div>That looks elegant.</div><div><br></div><div>But we should also try to support optional arguments and keyword arguments.</div><div><br></div><div>Also, some groups of people would like to see a more concise notation for lambdas, and maybe they'd want to write</div><div><br></div><div>x = (a, b) -> a + b</div><div><br></div><div>as sugar for</div><div><br></div><div>x = lambda a, b: a + b<br></div><div><br></div><div>We probably can't have both, so we should at least decide which is more important.</div><div><br></div><div>Too bad we can't use Unicode arrows. :-)<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 24, 2019 at 2:30 PM Vaibhav Karve <<a href="mailto:vaibhavskarve@gmail.com">vaibhavskarve@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>(Note: This idea is about a particular static typecheking (typing?) annotation syntax).<br></div><div>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?</div><div>Example:</div><div><br></div><div>Currently we write:<br></div><div> f: Callable[[int, Dict[str, int]], str] # declaring the type of some fake function<br></div><div><br></div><div>This would be much cleaner if we could write:</div><div> f: int -> Dict[str, int] -> str # One of the possibilities</div><div><br></div><div>or even:<br></div><div> f: int, Dict[str, int] -> str # Another possibility</div><div><br></div><div>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:</div><div>a) Not have to spell out Callable</div><div>b) Not have to use all those square brackets</div><div>c) Have the same notation work for both the function annotation as well as for declaring the type.</div><div><br></div><div>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.</div><div>Vaibhav Karve<br></div></div>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div><div><i style="font-family:Arial,Helvetica,sans-serif;font-size:small;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);color:rgb(136,136,136)"><span>Pronouns</span>: he/him/his </i><a href="http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/" style="color:rgb(17,85,204);font-family:Arial,Helvetica,sans-serif;font-size:small;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)" target="_blank"><i>(why is my <span>pronoun</span> here?)</i></a></div></div></div>