[Python-3000] Type annotations: annotating generators

Collin Winter collinw at gmail.com
Sat May 20 03:39:01 CEST 2006


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.

Collin Winter


More information about the Python-3000 mailing list