<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Aug 14, 2014 at 8:55 PM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Thu, Aug 14, 2014 at 12:28:26PM +0200, Manuel Cerón wrote:<br>
<br>
> One interesting feature of TypeScript is that it allows you to annotate<br>
> existing code without modifying it, by using external definition files. In<br>
> the JavaScript world, many people have contributed TypeScript annotation<br>
> files for popular JS libraries (<a href="http://definitelytyped.org/" target="_blank">http://definitelytyped.org/</a>).<br>
><br>
> I think this is possible in Python as well doing something like this:<br>
><br>
> @annotate('math.ciel')<br>
> def ciel(x: float) -> int:<br>
> pass<br>
<br>
</div>I'm afraid I don't understand what the annotate decorator is doing here.<br>
Can you explain please?<br></blockquote><div><br></div><div>The idea is to add type annotations to modules without modifying them. For example, in this case, the stdlib math module is defined and implemented in C, but you still want to have annotations for it so that if you write math.ciel('foo'), the static type analyzer gives you a error or warning. By defining a new module, for example math_annotations.py with empty functions with annotated signatures, you can let the static analyzer know what are the annotations for another module. In this example, the annotate decorator is just a way of telling the static analyzer that these annotations apply to the math.ceil function, not math_annotations.ceil.</div>
<div><br></div><div>This is what TypeScript does to annotate popular libraries written in plain JavaScript with zero type information. </div><div><br></div><div>Manuel.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><br>
<br>
<br>
<br>
--<br>
Steven<br>
_______________________________________________<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" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</div></div></blockquote></div><br></div></div>