[Python-3000] Adaptation and type declarations

Guido van Rossum guido at python.org
Mon Apr 10 22:48:56 CEST 2006


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:clip_to_int_range(0,10)): ...
>     def f(a:int_in_range(0,10)): ...
>     def f(a:clip_to_number_range(0,10)): ...
>     def f(a:number_in_range(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*.

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list