[Python-ideas] Syntax for key-value iteration over mappings

Sven R. Kunze srkunze at mail.de
Mon Jul 27 18:02:18 CEST 2015

On 27.07.2015 17:45, Lennart Regebro wrote:
> On Mon, Jul 27, 2015 at 5:30 PM, Sven R. Kunze <srkunze at mail.de> wrote:
>> I cannot follow. There is nothing about 'await' that tells me it can only be
>> used with coroutines. I need to memorize that fact, too.
> No, because you get a syntax error when you use it incorrectly, so you
> don't need to memorize that.
> But here it works only with specific types.
What's the difference?

> Well, that is going to be the case now as well, you can't get away from that.
Is it? I don't think so. There are many case where this is not the case.

>>> Both are quite incomprehensible unless you know exactly what is going
>>> on and that this is a shortcut for "fox x,y in foo.items():"
>> Same goes for .items(). It took some time to internalize this special case
>> (at least from my perspective).
> Sure, but now you have to learn what it is a special case of. All you
> did was hide that it calls .items(), so the error message "foo does
> not have an attribute 'items'" becomes harder to understand. You would
> need to change that error to something else. And it really should be,
> as you say, a SyntaxError, but it's a SyntaxError that can only be
> raise in runtime. Which I think breaks most peoples understandning of
> what a SyntaxError is...
Nobody said it should be either. That is tiny detail and of course it 
should be a comprehensible error message.

Btw. no newbie really knows what happens if they execute the default 
'for' loop. You could say as well: "don't implement 'for' loops because 
they hide the fact of calling 'next'".

More information about the Python-ideas mailing list