[Python-3000] Adaptation and type declarations

John Williams shponglespore at gmail.com
Tue Apr 11 18:45:58 CEST 2006


On 4/10/06, Guido van Rossum <guido at python.org> wrote:
> A bit more than a year ago I blogged extensively about this. The only
> syntax that is acceptable to me is slightly different; the above would
> look like
>
> def fn(a: Seq, b: Index, c: Text = "default"): ...
>
> where Seq, Index and Text can be expressions (the main problem with
> the syntax you propose is that the type can't be much more than an
> identifier before it gets ambiguous or unreadable).

I appologize if this has been suggested before, but what about this instead?

@mydecorator
def fn(a @Seq, b @Index, c @Text = default): ...

My rationale is that since type annotations are primarily useful with
decorators, they should have a syntax that is reminiscent of
decorators. The downside is that type annotations don't have anything
like the semantics of decorators, but I think the risk of confusion is
very small if decorators and type annotations are documented together
(as IMHO they should be in any case).

The "@" stands out far too much in a variable-width font, so I've
attached an HTML file to show how both syntaxes look with syntax
highlighting and a fixed-width font.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20060411/9923b921/attachment.html 


More information about the Python-3000 mailing list