Skip to content

bpo-38415 @asynccontextmanager as decorators like @contextmanager - #16667

Merged
ambv merged 1 commit into
python:mainfrom
fried:asynccontextmanager_decorator
Sep 23, 2021
Merged

bpo-38415 @asynccontextmanager as decorators like @contextmanager#16667
ambv merged 1 commit into
python:mainfrom
fried:asynccontextmanager_decorator

Conversation

@fried

@friedfried commented Oct 8, 2019

Copy link
Copy Markdown
Contributor

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

1st1 commented Oct 8, 2019

Copy link
Copy Markdown
Member

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
@fried
friedforce-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

fried commented Oct 8, 2019

Copy link
Copy Markdown
ContributorAuthor

alright

@1st1

1st1 commented Oct 8, 2019

Copy link
Copy Markdown
Member

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

@ambv
ambvforce-pushed the asynccontextmanager_decorator branch from cd79d6c to 8890d0eCompareSeptember 23, 2021 21:02
@ambv

ambv commented Sep 23, 2021

Copy link
Copy Markdown
Contributor

Rebased on current main (3.11).

@ambv
ambv merged commit 86b833b into python:mainSep 23, 2021
Comment threadLib/contextlib.py
Comment on lines +194 to +201
def __call__(self, func):
@wraps(func)
async def inner(*args, **kwds):
async with self.__class__(self.func, self.args, self.kwds):
return await func(*args, **kwds)

return inner

Copy link
Copy Markdown
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