[Python-Dev] async __setitem__

Nick Coghlan ncoghlan at gmail.com
Sat Jun 20 15:55:41 CEST 2015

On 19 June 2015 at 22:56, Martin Teichmann <lkb.teichmann at gmail.com> wrote:
> to get something out of the database. But getting something in, I have
> to write something like
>     await table.set(key, value)
> It would be cool if I could just write
>     await table[key] = value

You've introduced an ambiguity here, though, as you're applying
async/await to a statement without a leading keyword.

In "await expr" it's clear "expr" is expected to produce an Awaitable,
and the await expression waits for it.

In "async for" and "async with" it's clearly a modifier on the
respective keyword, and hence serves as a good mnemonic for switching
to the asynchronous variants of the relevant protocols.

But what does an "asynchronous assignment" do? Do we need __asetattr__
and __asetitem__ protocols, and only allow it when the target is a
subscript operation or an attribute? What if we're assigning to
multiple targets, do the run in parallel? How is tuple unpacking
handled? How is augmented assignment handled?

If we allow asynchronous assignment, do we allow asynchronous deletion as well?

As you start working through some of those possible implications of
offering an asynchronous assignment syntax, the explicit method based
"await table.set(key, value)" construct may not look so bad after all


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list