[Python-3000] Type annotations: annotating generators

Guido van Rossum guido at python.org
Sat May 20 05:25:56 CEST 2006


On 5/19/06, Collin Winter <collinw at gmail.com> wrote:
> On 5/19/06, Collin Winter <collinw at gmail.com> wrote:
> > Let's go back to Function(<type>, <type>, ..., returns=<type>)
>
> I just finished converting typecheck's test suite to use this
> notation, and I have the following to report: ick.
>
> The main problem is when the function returns a complex type:
>
> >>> Function(int, int, returns=(int, int))
> or:
> >>> Function(returns=(int, int))
>
> I find the latter even worse than the former.
>
> I played around, switching it back and forth between the above and
>
> >>> Function(int, int).returns(int, int)
> and
> >>> Function().returns(int, int)
>
> Using the methods, though, does mean you might end up with something
> like this when it comes to changing the Function()'s strictness:
>
> >>> Function(int, int, int).returns(int, int).is_strict(True)
>
> However, you can change the strictness settings for all Function()s
> using the class-level Function.default_strict attribute; I imagine
> most people wanting to change strictness will do so via the class, not
> the individual instances. I expect the majority of usages to look
> like:
>
> >>> Function(<type>, <type>, <type>).returns(<type>, <type>)
>
> ...with which I am pleased muchly.

OK; for the return value (only) the Function().returns(<type>)
notation does look fairly pretty.

I presume that return(int, int) is the same as return((int, int))?

Weren't we going to write a tuple of two ints as tuple[int, int]
though? Is (int, int) now just an alias for that or does it have a
different meaing?

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


More information about the Python-3000 mailing list