GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-38415 @asynccontextmanager as decorators like @contextmanager by fried · Pull Request #16667 · python/cpython

Conversation

@fried

@fried fried commented Oct 8, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@fried
fried requested a review from 1st1 as a code owner October 8, 2019 20:53
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Oct 8, 2019
@bedevere-bot bedevere-bot added the awaiting review label Oct 8, 2019
@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.

fried reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

1st1
1st1 approved these changes Oct 8, 2019
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Oct 8, 2019
@fried fried changed the title bpo: 38415 @asynccontextmanager as decorators like @contextmanager bpo:38415 @asynccontextmanager as decorators like @contextmanager Oct 8, 2019
@fried
fried force-pushed the asynccontextmanager_decorator branch from b6fad49 to cd79d6c Compare October 8, 2019 21:09
@fried fried changed the title bpo:38415 @asynccontextmanager as decorators like @contextmanager bpo-38415 @asynccontextmanager as decorators like @contextmanager Oct 8, 2019
@fried

fried commented Oct 8, 2019

Copy link
Copy Markdown
Contributor Author

alright

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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.

fried reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

asvetlov
asvetlov approved these changes Oct 15, 2019
View reviewed changes
@fried @ambv
bpo-38415 asynccontextmanagers as decorators
8890d0e
@ambv
ambv force-pushed the asynccontextmanager_decorator branch from cd79d6c to 8890d0e Compare September 23, 2021 21:02
@ambv

ambv commented Sep 23, 2021

Copy link
Copy Markdown
Contributor

Rebased on current main (3.11).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv
ambv merged commit 86b833b into python:main Sep 23, 2021
@bedevere-bot bedevere-bot removed the awaiting merge label Sep 23, 2021
graingert
graingert reviewed Dec 23, 2021
View reviewed changes
Comment thread Lib/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

@graingert graingert Dec 23, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@graingert graingert mentioned this pull request Dec 23, 2021
bpo-38415: Remove redundant AsyncContextDecorator.__call__ override from _AsyncG… #30233
Merged
@fried
fried deleted the asynccontextmanager_decorator branch September 24, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@graingert graingert graingert left review comments
@1st1 1st1 1st1 approved these changes
@asvetlov asvetlov asvetlov approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@fried @1st1 @ambv @asvetlov @graingert @the-knights-who-say-ni @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.