[Python-3000] Misc type annotation issues

Nick Coghlan ncoghlan at gmail.com
Sun May 21 03:27:37 CEST 2006


Guido van Rossum wrote:
> On 5/20/06, Collin Winter <collinw at gmail.com> wrote:
>> 3. What will annotations on *varargs and **varkw look like? My own
>> suggestion is that
>>
>>>>> def foo(a: <type>, *varargs: <type>, **varkw: <type>)
>> is fully equivalent to -- and is indeed coerced to --
>>
>>>>> def foo(a: <type>, *varargs: list[<type>], **varkw: dict[str, <type>])
>> What did you have in mind?
> 
> We can't allow both the shorthand and the full notation, since then
> there would be ambiguity: if "*args: int" meant the same as "*args:
> list[int]", then what if I want each of the remaining positional
> arguments to be a list of ints? "*args: list[int]" is already taken to
> mean that each of the remaining arguments is an int.
> 
> Since the full notation is unnecessarily verbose, I propose that
> "*args: T" means that each of the remaining arguments should be a T,
> and the type of args itself is list[T]. Similar for **kwds.

That last paragraph is actually the way I interpreted Collin's suggestion (due 
to the "coerced to" comment).

And I trust "*args : T" would actually map to a type annotation of tuple[T] 
for the args variable ;)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list