[Python-3000] optional argument annotations

Tony Lownds tony at pagedna.com
Fri Nov 24 18:59:03 CET 2006


On Nov 24, 2006, at 8:30 AM, Guido van Rossum wrote:

>> I would rather see it integrated into a Signature object (Brett  
>> had an
>> implementation), instead of showing up as two separate attributes.
>
> Yes, you're right; I forgot about that.
>

I'd imagine that the Signature object would live on top of this change.

>>>>>>> f.func_returns
>>>> Traceback (most recent call last):
>>>>    File "<stdin>", line 1, in <module>
>>>> AttributeError: 'function' object has no attribute 'func_returns'
>>
>>> I would prefer this to be None. Attributes that don't always  
>>> exist are
>>> a pain to use.
>>
>> I suspect he was trying to distinguish "returns None" from "Doesn't
>> say what it returns".  There is no good way to do this, but a  
>> separate
>> flag on a Signature object seems the least bad to me.
>
> Hm, I think it would be fine if there *was* no distinction. IOW if
>
>   def foo(a: None) -> None: pass
>
> was indistinguishable from
>
>   def foo(a): pass
>
> In fact I think I'd prefer it that way. Having an explicit way to say
> "no type here, move along" sounds fine. It's different from defaults,
> whose absence translates in different behavior (i.e., requiring that a
> value be passed in).
>
> (It does imply that we can't use "-> None" to indicate "returns no
> value". We'd have to spell that as "-> type(None)" or find some other
> way. I think I don't care. Do others? Collin?)
>

That's fine with me, but just to toss out another idea: we could put the
return annotation in func_annotations['return'].

-Tony




More information about the Python-3000 mailing list