diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2018-10-26 11:19:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-26 11:19:14 (GMT) |
commit | 7cd25434164882c2093ea41ccfc7b95a05cd5cbd (patch) | |
tree | 76c33543b495e78b0e520dd4914da68dcf616dae /Lib/test/test_inspect.py | |
parent | e483f02423917dc4dfd25f46e5b9e6fce304777d (diff) | |
download | cpython-7cd25434164882c2093ea41ccfc7b95a05cd5cbd.zip cpython-7cd25434164882c2093ea41ccfc7b95a05cd5cbd.tar.gz cpython-7cd25434164882c2093ea41ccfc7b95a05cd5cbd.tar.bz2 |
bpo-34890: Make iscoroutinefunction, isgeneratorfunction and isasyncgenfunction work with functools.partial (GH-9903)
inspect.isfunction() processes both inspect.isfunction(func) and
inspect.isfunction(partial(func, arg)) correctly but some other functions in the
inspect module (iscoroutinefunction, isgeneratorfunction and isasyncgenfunction)
lack this functionality. This commits adds a new check in the mentioned functions
in the inspect module so they can work correctly with arbitrarily nested partial
functions.
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r-- | Lib/test/test_inspect.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 134b0cd..b9072e0 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -166,26 +166,51 @@ class TestPredicates(IsTestBase): self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days)) def test_iscoroutine(self): + async_gen_coro = async_generator_function_example(1) gen_coro = gen_coroutine_function_example(1) coro = coroutine_function_example(1) self.assertFalse( inspect.iscoroutinefunction(gen_coroutine_function_example)) + self.assertFalse( + inspect.iscoroutinefunction( + functools.partial(functools.partial( + gen_coroutine_function_example)))) self.assertFalse(inspect.iscoroutine(gen_coro)) self.assertTrue( inspect.isgeneratorfunction(gen_coroutine_function_example)) + self.assertTrue( + inspect.isgeneratorfunction( + functools.partial(functools.partial( + gen_coroutine_function_example)))) self.assertTrue(inspect.isgenerator(gen_coro)) self.assertTrue( inspect.iscoroutinefunction(coroutine_function_example)) + self.assertTrue( + inspect.iscoroutinefunction( + functools.partial(functools.partial( + coroutine_function_example)))) self.assertTrue(inspect.iscoroutine(coro)) self.assertFalse( inspect.isgeneratorfunction(coroutine_function_example)) + self.assertFalse( + inspect.isgeneratorfunction( + functools.partial(functools.partial( + coroutine_function_example)))) self.assertFalse(inspect.isgenerator(coro)) - coro.close(); gen_coro.close() # silence warnings + self.assertTrue( + inspect.isasyncgenfunction(async_generator_function_example)) + self.assertTrue( + inspect.isasyncgenfunction( + functools.partial(functools.partial( + async_generator_function_example)))) + self.assertTrue(inspect.isasyncgen(async_gen_coro)) + + coro.close(); gen_coro.close(); # silence warnings def test_isawaitable(self): def gen(): yield |