Skip to content

Conversation

@fried
Copy link
Contributor

@friedfried commented Oct 8, 2019

I assumed at that an asynccontextmanager would some time be available in the stdlib when we first got async generators. Before it had been released I cooked up an internal version at facebook whiched mapped all the features of @contextmanager but as an async variant. This one feature seems to be missing from the stdlib.

I would like to stop using my version and just use the stdlib version, can we get this feature parity with contextmanager?

@asynccontextmanager async def our_context(...): ... yield ... @our_context(...) async def some_function(...): # we are inside the context of our_context now ... @our_context(...) async def some_other_function(...): ... 

https://bugs.python.org/issue38415

@1st1
Copy link
Member

1st1 commented Oct 8, 2019

Awesome! Please create a bpo issue and generate a NEWS file using the blurb tool.

1st1
1st1 approved these changes Oct 8, 2019
@friedfried changed the title bpo: 38415 @asynccontextmanager as decorators like @contextmanagerbpo:38415 @asynccontextmanager as decorators like @contextmanagerOct 8, 2019
@friedfriedforce-pushed the asynccontextmanager_decorator branch from b6fad49 to cd79d6cCompareOctober 8, 2019 21:09
@friedfried changed the title bpo:38415 @asynccontextmanager as decorators like @contextmanagerbpo-38415 @asynccontextmanager as decorators like @contextmanagerOct 8, 2019
@fried
Copy link
ContributorAuthor

fried commented Oct 8, 2019

alright

@1st1
Copy link
Member

1st1 commented Oct 8, 2019

@ncoghlan Nick, do you want to take a look at this? Looks good to me.

@ambvambvforce-pushed the asynccontextmanager_decorator branch from cd79d6c to 8890d0eCompareSeptember 23, 2021 21:02
@ambv
Copy link
Contributor

ambv commented Sep 23, 2021

Rebased on current main (3.11).

@ambvambv merged commit 86b833b into python:mainSep 23, 2021
Comment on lines +194 to +201
def__call__(self, func):
@wraps(func)
asyncdefinner(*args, **kwds):
asyncwithself.__class__(self.func, self.args, self.kwds):
returnawaitfunc(*args, **kwds)

returninner

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is now redundant - support for asynccontextmanagers as decorators was added in #20516

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@fried@1st1@ambv@asvetlov@graingert@the-knights-who-say-ni@bedevere-bot