8000 bpo-40816 Add AsyncContextDecorator class by heckad · Pull Request #20516 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-40816 Add AsyncContextDecorator class #20516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 5, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test
  • Loading branch information
heckad committed Jul 20, 2020
commit 858a98fbe9446e4ec781b7f3caaf90505ce2ca23
19 changes: 19 additions & 0 deletions Lib/test/test_contextlib_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,25 @@ async def woohoo(self, func, args, kwds):
async with woohoo(self=11, func=22, args=33, kwds=44) as target:
self.assertEqual(target, (11, 22, 33, 44))

async def test_recursive(self):
depth = 0
@asynccontextmanager
async def woohoo():
nonlocal depth
before = depth
depth += 1
yield
depth -= 1
self.assertEqual(depth, before)

@woohoo()
async def recursive():
if depth < 10:
recursive()

await recursive()
self.assertEqual(depth, 0)


class TestAsyncExitStack(TestBaseExitStack, unittest.TestCase):
class SyncAsyncExitStack(AsyncExitStack):
Expand Down
0