aiohttp icon indicating copy to clipboard operation
aiohttp copied to clipboard

Accepting async context managers for cleanup contexts

Open achimnol opened this issue 2 months ago • 3 comments

Is your feature request related to a problem?

Typing application-level resource init & cleanup contexts with contextlib.asynccontextmanager makes them unusable as aiohttp's cleanup contexts, though the concept is same.

Describe the solution you'd like

Currently cleanup contexts are expected to be async generators, which should have only one yield. Since it's been a long time after addition of contextlib.asynccontextmanager in the stdlib, I think it should accept them in addition to single-yielding async generators.

Describe alternatives you've considered

Completely changing cleanup contexts from async generators to async context managers would make it incompatible with existing codes, so we need to make it accept both.

Related component

Server

Additional context

No response

Code of Conduct

  • [x] I agree to follow the aio-libs Code of Conduct

achimnol avatar Oct 17 '25 06:10 achimnol

Yeah, sounds like a good idea.

Dreamsorcerer avatar Oct 17 '25 12:10 Dreamsorcerer

I can work on this one if it's ok?

MannXo avatar Oct 21 '25 07:10 MannXo

Yeah, go ahead.

Dreamsorcerer avatar Oct 21 '25 12:10 Dreamsorcerer