Visitar URL original
gh-79940: add introspection API for asynchronous generators by tkren · Pull Request #11590 · python/cpython · GitHub
Skip to content
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
inspect: use anext() built-in in TestGetAsyncGenState
  • Loading branch information
tkren committed Mar 10, 2023
commit 1931c0b24d9809cbc91bcd8b6b173cee5d29b93c
20 changes: 10 additions & 10 deletions Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2343,15 +2343,15 @@ def test_created(self):

def test_suspended(self):
try:
next(self.asyncgen.__anext__())
next(anext(self.asyncgen))
except StopIteration as exc:
self.assertEqual(self._asyncgenstate(), inspect.AGEN_SUSPENDED)
self.assertEqual(exc.args, (0,))
Comment thread
tkren marked this conversation as resolved.
Outdated

def test_closed_after_exhaustion(self):
while True:
try:
next(self.asyncgen.__anext__())
next(anext(self.asyncgen))
except StopAsyncIteration:
self.assertEqual(self._asyncgenstate(), inspect.AGEN_CLOSED)
break
Expand All @@ -2375,12 +2375,12 @@ async def running_check_asyncgen():
self.asyncgen = running_check_asyncgen()
# Running up to the first yield
try:
next(self.asyncgen.__anext__())
next(anext(self.asyncgen))
except StopIteration:
pass
# Running after the first yield
try:
next(self.asyncgen.__anext__())
next(anext(self.asyncgen))
except StopIteration:
pass

Expand All @@ -2404,28 +2404,28 @@ async def each(lst, a=None):
self.assertEqual(inspect.getasyncgenlocals(numbers),
{'a': None, 'lst': [1, 2, 3]})
try:
next(numbers.__anext__())
next(anext(numbers))
except StopIteration:
pass
self.assertEqual(inspect.getasyncgenlocals(numbers),
{'a': None, 'lst': [1, 2, 3], 'v': 1,
'b': (1, 2, 3)})
try:
next(numbers.__anext__())
next(anext(numbers))
except StopIteration:
pass
self.assertEqual(inspect.getasyncgenlocals(numbers),
{'a': None, 'lst': [1, 2, 3], 'v': 2,
'b': (1, 2, 3)})
try:
next(numbers.__anext__())
next(anext(numbers))
except StopIteration:
pass
self.assertEqual(inspect.getasyncgenlocals(numbers),
{'a': None, 'lst': [1, 2, 3], 'v': 3,
'b': (1, 2, 3), 'c': 12})
try:
next(numbers.__anext__())
next(anext(numbers))
except StopAsyncIteration:
pass
self.assertEqual(inspect.getasyncgenlocals(numbers), {})
Expand All @@ -2436,12 +2436,12 @@ async def yield_one():
one = yield_one()
self.assertEqual(inspect.getasyncgenlocals(one), {})
try:
next(one.__anext__())
next(anext(one))
except StopIteration:
pass
self.assertEqual(inspect.getasyncgenlocals(one), {})
try:
next(one.__anext__())
next(anext(one))
except StopAsyncIteration:
pass
self.assertEqual(inspect.getasyncgenlocals(one), {})
Expand Down