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

Lennart Regebro regebro at gmail.com
Mon Jul 27 17:45:25 CEST 2015

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.

> I would like such an error. Because it tells me that it is not what I
> wanted. The current methods silently works and I get an error later.

Well, that is going to be the case now as well, you can't get away from that.

>> 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...


More information about the Python-ideas mailing list