[Python-ideas] Trial balloon: adding variable type declarations in support of PEP 484

Guido van Rossum guido at python.org
Mon Aug 1 19:31:38 EDT 2016


On Mon, Aug 1, 2016 at 2:46 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 08/01/2016 02:31 PM, Guido van Rossum wrote:
>
>> Third, there's an annoying thing with tuples/commas here. On the one
>> hand, in a function declaration, we may see (a: int = 0, b: str = '').
>> On the other hand, in an assignment, we may see
>>
>> a, b = 0, ''
>>
>> Suppose we wanted to add types to the latter. Would we write this as
>>
>> a: int, b: str = 0, ''
>
>
> If keeping it all on one line, I find this far more readable:
>
> - it keeps the type right next the name (imagine if there five names and
> types)
> - it mirrors the function header style (one less thing to remember)

But what would this do?

a: int, b: str = x

Does the x get distributed over (a, b) or does a remain unset? The
analogy with assignment suggest that x gets distributed, but the
analogy with function definitions says x only goes to b.

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-ideas mailing list