Repository navigation
bpo-34890: Make iscoroutinefunction, isgeneratorfunction and isasyncgenfunction work with functools.partial #9903
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
Changes from 3 commits
633c497
41f7f60
b65500e
3b841ac
adb5db6
617688e
caddd21
0585757
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| import collections | ||
| import datetime | ||
| import functools | ||
| from functools import partial | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use module import (i.e.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in adb5db6. I did that originally to simplify the double |
||
| import importlib | ||
| import inspect | ||
| import io | ||
|
|
@@ -166,26 +167,46 @@ def test_excluding_predicates(self): | |
| 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( | ||
| partial(partial(gen_coroutine_function_example)))) | ||
| self.assertFalse(inspect.iscoroutine(gen_coro)) | ||
|
|
||
| self.assertTrue( | ||
| inspect.isgeneratorfunction(gen_coroutine_function_example)) | ||
| self.assertTrue( | ||
| inspect.isgeneratorfunction( | ||
| partial(partial(gen_coroutine_function_example)))) | ||
| self.assertTrue(inspect.isgenerator(gen_coro)) | ||
|
|
||
| self.assertTrue( | ||
| inspect.iscoroutinefunction(coroutine_function_example)) | ||
| self.assertTrue( | ||
| inspect.iscoroutinefunction( | ||
| partial(partial(coroutine_function_example)))) | ||
| self.assertTrue(inspect.iscoroutine(coro)) | ||
|
|
||
| self.assertFalse( | ||
| inspect.isgeneratorfunction(coroutine_function_example)) | ||
| self.assertFalse( | ||
| inspect.isgeneratorfunction( | ||
| partial(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( | ||
| partial(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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Make :func:`inspect.iscoroutinefunction`, | ||
| :func:`inspect.isgeneratorfunction` and :func:`inspect.isasyncgenfunction` | ||
| work with :func:`functools.partial`. Patch by Pablo Galindo. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also document the change with a ".. versionchanged:: 3.8" markup in https://docs.python.org/dev/library/inspect.html#inspect.isgeneratorfunction ? |
||
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.
Why don't we add an
_unwrap_partialhelper. Or.. should we maybe useinspect.unwrap()too?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.
Actually, let's not use
inspect.unwrap(). Decorating generators and coroutines isn't that common.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.
Do we still want the helper?
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.
I have done the refactor in 3b841ac