PEP 0492 __aenter__ & __aexit__

Hi Python-Dev Group, I am trying to implement __aenter__ and __aexit__ for the RethinkDB <https://rethinkdb.com> Python driver. Looking at the PEP I don't see any definitions as to what the expected parameters that __exit__ are supposed to take and couldn't find any other similar implementations. Is there a piece of documentation I should be looking at that I'm missing? https://www.python.org/dev/peps/pep-0492/#asynchronous-context-managers-and-... Many thanks, Daniel

On Sat, 6 Feb 2016 at 13:50 Daniel Miller <dalanmiller@rethinkdb.com> wrote:
The arguments to __aexit__ are the same as __exit__ in a normal context manager. See https://docs.python.org/3.5/reference/datamodel.html#object.__aexit__ for the official docs for __aexit__.

Awesome, I missed that. Thank you Brett. Am I understanding correctly that if I'd like to avoid `async with await EXPR` whatever is returned from EXPR must implement `__await__` as a non-coroutine method? Which then I'd just be able to use `async with ...`? 2016-02-06 16:05 GMT-06:00 Brett Cannon <brett@python.org>:

On Sun, 7 Feb 2016 at 08:17 Daniel Miller <dalanmiller@rethinkdb.com> wrote:
Awesome, I missed that. Thank you Brett.
Welcome!
Assuming I'm following what you're asking properly, __aenter__ needs to return an awaitable: https://docs.python.org/3/reference/datamodel.html?#awaitable-objects. That is either an object that implements __await__() or a coroutine (which is basically a generator decorated with types.coroutine).

On Mon, 8 Feb 2016 at 09:34 Yury Selivanov <yselivanov.ml@gmail.com> wrote:
Probably. Links around the Internet, search engines, etc. will point to the PEP for a while, and so knowing that the most up-to-date info is actually the docs and not the PEP would be good. I honestly just know all of this stuff because of a massive blog post I'm writing on async/await ATM. -Brett

On Sat, 6 Feb 2016 at 13:50 Daniel Miller <dalanmiller@rethinkdb.com> wrote:
The arguments to __aexit__ are the same as __exit__ in a normal context manager. See https://docs.python.org/3.5/reference/datamodel.html#object.__aexit__ for the official docs for __aexit__.

Awesome, I missed that. Thank you Brett. Am I understanding correctly that if I'd like to avoid `async with await EXPR` whatever is returned from EXPR must implement `__await__` as a non-coroutine method? Which then I'd just be able to use `async with ...`? 2016-02-06 16:05 GMT-06:00 Brett Cannon <brett@python.org>:

On Sun, 7 Feb 2016 at 08:17 Daniel Miller <dalanmiller@rethinkdb.com> wrote:
Awesome, I missed that. Thank you Brett.
Welcome!
Assuming I'm following what you're asking properly, __aenter__ needs to return an awaitable: https://docs.python.org/3/reference/datamodel.html?#awaitable-objects. That is either an object that implements __await__() or a coroutine (which is basically a generator decorated with types.coroutine).

On Mon, 8 Feb 2016 at 09:34 Yury Selivanov <yselivanov.ml@gmail.com> wrote:
Probably. Links around the Internet, search engines, etc. will point to the PEP for a while, and so knowing that the most up-to-date info is actually the docs and not the PEP would be good. I honestly just know all of this stuff because of a massive blog post I'm writing on async/await ATM. -Brett
participants (3)
-
Brett Cannon
-
Daniel Miller
-
Yury Selivanov