mirror of
https://github.com/python/cpython.git
synced 2025-10-21 22:22:48 +00:00
Issue #28003: Implement PEP 525 -- Asynchronous Generators.
This commit is contained in:
parent
b96ef55d49
commit
eb6364557f
27 changed files with 2189 additions and 96 deletions
|
@ -65,7 +65,8 @@ class IsTestBase(unittest.TestCase):
|
|||
inspect.isframe, inspect.isfunction, inspect.ismethod,
|
||||
inspect.ismodule, inspect.istraceback,
|
||||
inspect.isgenerator, inspect.isgeneratorfunction,
|
||||
inspect.iscoroutine, inspect.iscoroutinefunction])
|
||||
inspect.iscoroutine, inspect.iscoroutinefunction,
|
||||
inspect.isasyncgen, inspect.isasyncgenfunction])
|
||||
|
||||
def istest(self, predicate, exp):
|
||||
obj = eval(exp)
|
||||
|
@ -73,6 +74,7 @@ class IsTestBase(unittest.TestCase):
|
|||
|
||||
for other in self.predicates - set([predicate]):
|
||||
if (predicate == inspect.isgeneratorfunction or \
|
||||
predicate == inspect.isasyncgenfunction or \
|
||||
predicate == inspect.iscoroutinefunction) and \
|
||||
other == inspect.isfunction:
|
||||
continue
|
||||
|
@ -82,6 +84,10 @@ def generator_function_example(self):
|
|||
for i in range(2):
|
||||
yield i
|
||||
|
||||
async def async_generator_function_example(self):
|
||||
async for i in range(2):
|
||||
yield i
|
||||
|
||||
async def coroutine_function_example(self):
|
||||
return 'spam'
|
||||
|
||||
|
@ -122,6 +128,10 @@ class TestPredicates(IsTestBase):
|
|||
self.istest(inspect.isdatadescriptor, 'collections.defaultdict.default_factory')
|
||||
self.istest(inspect.isgenerator, '(x for x in range(2))')
|
||||
self.istest(inspect.isgeneratorfunction, 'generator_function_example')
|
||||
self.istest(inspect.isasyncgen,
|
||||
'async_generator_function_example(1)')
|
||||
self.istest(inspect.isasyncgenfunction,
|
||||
'async_generator_function_example')
|
||||
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue