zlacker

[parent] [thread] 0 comments
1. gcharb+(OP)[view] [source] 2025-05-30 21:39:01
async with is just syntactic sugar. You could very well call __aenter__ and __aexit__ manually. You could also use an AsyncExitStack, call __aenter__ manually, then enter_async_context, and call aclose when you’re done. Since aclose method exists I guess this is not an anti-pattern.

https://docs.python.org/3/library/contextlib.html#contextlib...

[go to top]