Sorry, something went wrong.
Sorry, something went wrong.
|
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.
|
@vstinner Can you take a look? |
Sorry, something went wrong.
|
this shouldn't be needed AsyncMock already sets Lines 2175 to 2178 in 5fcfdd8 |
Sorry, something went wrong.
There was a problem hiding this comment.
Why is this here instead of re-using asyncio.coroutines._is_coroutine?
Sorry, something went wrong.
There was a problem hiding this comment.
I moved it from asyncio to inspect as the code using it is now located in inspect module.
Sorry, something went wrong.
There was a problem hiding this comment.
_is_coroutine feels like a property of asyncio, not inspect. I think it should stay where it is.
Sorry, something went wrong.
|
this shouldn't be needed AsyncMock already sets Lines 2175 to 2178 in 5fcfdd8 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.
|
looks like this issue is because mock.AsyncMock() doesn't pass inspect.isfunction: 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.
|
Could CallableMixin mess about with __instancecheck__/__subclasscheck__/__class__ to pass isinstance(AsyncMock(), types.FunctionType)? |
Sorry, something went wrong.
|
Could CallableMixin mess about with __instancecheck__/__subclasscheck__/__class__ to pass isinstance(AsyncMock(), types.FunctionType)? I tried but this doesn't seem to work, I suspect this fall in isinstance C optimisation and __instancecheck__ and friends are never called. |
Sorry, something went wrong.
|
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.
|
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 According to the doc, the only difference is asyncio.iscoroutinefunction also works for deprecated generator based coroutine |
Sorry, something went wrong.
|
But, I agree that my solution doesn't work. We should keep the _is_coroutine hack as-is until generated coroutine are removed and found another solution to make isfunction pass for AsyncMock(). |
Sorry, something went wrong.
|
I found another solution, I think it's cleaner. |
Sorry, something went wrong.
There was a problem hiding this comment.
Can you try to preserve current coding style? Return early with False if a condition is false? Pseudo-code:
Sorry, something went wrong.
There was a problem hiding this comment.
done
Sorry, something went wrong.
|
GH-94460 is a backport of this pull request to the 3.11 branch. |
Sorry, something went wrong.
|
GH-94461 is a backport of this pull request to the 3.10 branch. |
Sorry, something went wrong.
|
Thanks all! That was fast 🚀 |
Sorry, something went wrong.
|
This change seems to have caused a regression reported in #96127 |
Sorry, something went wrong.
The inspect version was not working with unittest.mock.AsyncMock.
This change moves the asyncio fix for AsyncMock in inspect module and
make asyncio.iscoroutinefunction an alias of inspect.iscoroutinefunction.