I totally do not understand the requirement for the dictionary and its extra overhead.<br><br><div><span class="gmail_quote">On 8/15/06, <b class="gmail_sendername">Collin Winter</b> &lt;<a href="mailto:collinw@gmail.com">
collinw@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>@typechecker<br>def foo(a: {'type': Number},<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b: {'type': Number}) -&gt; {'type': Number}
<br><br><br>I'm going to raise the bar for future ideas on this subject: any<br>proposals must be able to address the following use cases:<br><br>1) Static analysis tools (pychecker, optimising compilers, etc) must<br>be able to use the annotations
<br>2) Decorator-based annotation consumers must be able to use the annotations<br>3) Non-decorator-based annotation consumers (pydoc, etc) must be able<br>to use the annotations</blockquote><div><br>Consider the following syntax:
<br><br>class MyType:<br>&nbsp;&nbsp; def __init__(self, name):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://self.name">self.name</a> = name<br><br>Number = MyType(&quot;Number&quot;)<br>Tuple = MyTime(&quot;Tuple&quot;)<br><br>def foo(a: tc(Number)) -&gt; Tuple(Number, Number)
<br></div><br>1. Static analysis tools can deal with this as much as with ANY truly Pythonic syntax. Their ability to deal will depend (as in any syntax) on their ability to do module or whole-program analysis. In your syntax, or mine, &quot;Number&quot; could be defined dynamically. In either case, someone could say &quot;Number = None&quot; and confuse everything.
<br><br>2. A decorator based anaysis could look at __signatures__ and do what it needs.<br><br>3. Similarly for non-decorator analyzers.<br><br>In fact, given that decorators are just syntactic sugar for function calls, I don't see why they should require special consideration at all. If the syntax works well for non-decorator consumers then decorators will be just a special case. As far as static analysis tools: Python has never made major concessions to them. Minor concessions, yes.
<br><br>I'd ask that you add the following requirement:<br><br>&nbsp;* must define how multiple annotation syntaxes can assign potentially differing meanings to built-in types and objects, on the same parameter, without actually conflicting
<br><br>My full program (meeting all requirements) follows.<br><br>&nbsp;Paul Prescod<br><br>====<br><br>def simulate_signature(sig):<br>&nbsp;&nbsp;&nbsp; &quot;simulates the signature feature of Pythn 3000&quot;<br>&nbsp;&nbsp;&nbsp; def _(func):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; func.__signature__ = sig
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return func<br>&nbsp;&nbsp;&nbsp; return _<br><br>def my_print_signature(func):<br>&nbsp;&nbsp;&nbsp; &quot;a demo decorator that prints signatures.&quot;<br>&nbsp;&nbsp;&nbsp; if hasattr(func, &quot;__signature__&quot;):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sig = func.__signature__
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [my_print_arg(name, value) for name, value in sig.items()]<br>&nbsp;&nbsp;&nbsp; return func<br><br>def my_print_arg(name, annotation):<br>&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;print a single argument's <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; declaration, skipping unknown anno types.&quot;&quot;&quot;
<br>&nbsp;&nbsp;&nbsp; if isinstance(annotation, list):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [my_print_arg(name, anno) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for anno in annotation]<br>&nbsp;&nbsp;&nbsp; elif conformsToInterface(annotation, MyType):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print name<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; annotation.print_arg
()<br><br>def conformsToInterface(object, interface):<br>&nbsp;&nbsp; &quot;naive implemenation of interfaces&quot;<br>&nbsp;&nbsp; return isinstance(object, interface)<br><br>class MyType:<br>&nbsp;&nbsp; def __init__(self, *children):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.children
 = children<br>&nbsp;&nbsp; def print_arg(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print self.children<br><br>#defined in your module. I have no knowledge of it<br>class YourType:<br>&nbsp;&nbsp; def __init__(self, *stuff):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass<br><br># a simple signature
<br><br># real syntax should be:<br># def foo(bar: MyType(int))<br>@simulate_signature({&quot;bar&quot;: MyType(int)})<br>def foo(bar):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (bar, bar)<br><br># use print signature decorator<br><br># real syntax should be:
<br>
# def foo2(bar: [MyType(int)...]) -&gt; [MyType(...]<br>
@my_print_signature<br>@simulate_signature({&quot;bar&quot;: [MyType(int), YourType(&quot;int&quot;)], <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;return&quot;: [MyType(tuple([int, int])),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YourType(&quot;tuple of int,int&quot;)]})
<br>def foo2(bar):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (bar, bar)<br><br># can also be used as non-decorator<br>for name, val in vars().items():<br>&nbsp;&nbsp;&nbsp; my_print_signature(val)<br><br></div>