[Python-3000] Adaptation and type declarations (original) (raw)

Tim Hochberg tim.hochberg at ieee.org
Mon Apr 10 23:03:14 CEST 2006


Guido van Rossum wrote:

On 4/10/06, Jim Jewett <jimjjewett at gmail.com> wrote:

On 4/10/06, Guido van Rossum <guido at python.org> wrote:

A completely separate issue is what kind of objects Seq, Index and Text would be; but that's a discussion we have separate from the syntactic discussion. What do you mean? The only question that leaps out at me is whether they should be predicates or constructors. In other words, should def f(a:Seq): ... mean something closer to def f(a): assert Seq(a) ... or def f(a): a=Seq(a) ... It should mean neither. As I tried to say, the only semantics is that the value of the expression is accessible through the signature attribute of the function. It is then up to the decorator to decide what it means. If adaptation is light enough to be useful, then I can't see any reason to prefer the first. def f(a:0<a<10): ... isn't that much cleaner than whichever of def f(a:cliptointrange(0,10)): ... def f(a:intinrange(0,10)): ... def f(a:cliptonumberrange(0,10)): ... def f(a:numberinrange(0,10)): ... was actually intended. That's not something I had considered. It would have to turn the expression into an implicit lambda (or an AST), which isn't something we should do lightly, and which conflicts with other proposed uses, where the value of the expression is made available to the decorator -- the value of '0<a<10' is not available until f is called.

This seems like it ties into the AST access thread. If some way of quoting little chunks of code shows up, this becomes a non-problem since you can then do:

 def f(a:`0<a<10`)

[I'm using backquotes for the moment since that's the only syntax I've seen proposed] Then the responsibility falls to decorator to something sensible with the code fragment. Turning the type specifier into some sort of implicit lambda seems like a mess otherwise.

Regards,

-tim



More information about the Python-3000 mailing list