GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-84753: Make inspect.iscoroutinefunction() work with AsyncMock by sileht · Pull Request #94050 · python/cpython Conversation
|
|
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@vstinner Can you take a look? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
this shouldn't be needed AsyncMock already sets Lines 2175 to 2178 in 5fcfdd8
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why is this here instead of re-using asyncio.coroutines._is_coroutine?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I moved it from asyncio to inspect as the code using it is now located in inspect module.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
_is_coroutine feels like a property of asyncio, not inspect. I think it should stay where it is.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The test cases I added passed was passing for asyncio version, but was not for the inspect version. So something doesn't work as expected. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
looks like this issue is because from unittest import mock import inspect m = mock.AsyncMock() with mock.patch("inspect.isfunction", new=lambda x: True): assert inspect.iscoroutinefunction(m) Originally posted by @graingert in #84753 (comment) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Could CallableMixin mess about with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I tried but this doesn't seem to work, I suspect this fall in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm relying on inspect.iscoroutinefunction to reveal things that really really are Coroutine Functions, partials or methods and asyncio.iscoroutinefunction to reveal things that are Duck typed as a Coroutine Function |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
According to the doc, the only difference is |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
But, I agree that my solution doesn't work. We should keep the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I found another solution, I think it's cleaner. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
fe4fc4e to
970f727
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Can you try to preserve current coding style? Return early with False if a condition is false? Pseudo-code:
if not isfunction(f): return False
if not _signature_is_functionlike(f): return False
return bool(f.__code__.co_flags & flag)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
pythonGH-94050) The inspect version was not working with unittest.mock.AsyncMock. The fix introduces special-casing of AsyncMock in `inspect.iscoroutinefunction` equivalent to the one performed in `asyncio.iscoroutinefunction`. Co-authored-by: Łukasz Langa <[email protected]> (cherry picked from commit 4261b6b) Co-authored-by: Mehdi ABAAKOUK <[email protected]>
|
GH-94460 is a backport of this pull request to the 3.11 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
pythonGH-94050) The inspect version was not working with unittest.mock.AsyncMock. The fix introduces special-casing of AsyncMock in `inspect.iscoroutinefunction` equivalent to the one performed in `asyncio.iscoroutinefunction`. Co-authored-by: Łukasz Langa <[email protected]> (cherry picked from commit 4261b6b) Co-authored-by: Mehdi ABAAKOUK <[email protected]>
|
GH-94461 is a backport of this pull request to the 3.10 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks all! That was fast 🚀 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…94050) (GH-94461) The inspect version was not working with unittest.mock.AsyncMock. The fix introduces special-casing of AsyncMock in `inspect.iscoroutinefunction` equivalent to the one performed in `asyncio.iscoroutinefunction`. Co-authored-by: Łukasz Langa <[email protected]> (cherry picked from commit 4261b6b) Co-authored-by: Mehdi ABAAKOUK <[email protected]>
…94050) (GH-94460) The inspect version was not working with unittest.mock.AsyncMock. The fix introduces special-casing of AsyncMock in `inspect.iscoroutinefunction` equivalent to the one performed in `asyncio.iscoroutinefunction`. Co-authored-by: Łukasz Langa <[email protected]> (cherry picked from commit 4261b6b) Co-authored-by: Mehdi ABAAKOUK <[email protected]>
The wording used in pythonGH-94050 suggests narrower scope than what was actually implemented. This commit clarifies the full impact of pythonGH-94050 in the change log.
|
This change seems to have caused a regression reported in #96127 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.