mock.Mock() acts like a Future
popravich opened this issue · 12 comments
Since this changes 32edb29 unittest.mock.Mock
being detected
as asyncio.Future
.
asyncio.futures.isfuture
checks for private attribute _asyncio_future_blocking
to be not None
and Mock()
(without specs) returns new mock as this attribute.
The use case is here aio-libs-abandoned/aioredis-py#161 — basically, function wrapped with asyncio.coroutine
and set as Mock
's method side_effect
started to raise TypeError
.
We can probably check obj.__class__
for _asyncio_future_blocking
attribute.
Is there something you want us to do?
Yeah, it was more like FYI.
Maybe a little bit stricter check would be better.
Some use cases like implementing some kind of RPC with dynamic methods resolution might hit this case
@gvanrossum Please see #455.
I'm not at all clear that a Mock should not be considered a Future. The clarification "Some use cases like implementing some kind of RPC with dynamic methods resolution" sounds awefully vague. Maybe there are just as many use cases that would break with this change?
Maybe there are just as many use cases that would break with this change?
isinstance(unittest.mock.Mock(), asyncio.Future)
returns False
. If we want to promote to use isfuture
instead of isinstance
, we should fix it.
isinstance(unittest.mock.Mock(), asyncio.Future) returns False. If we
want to promote to use isfuture instead of isinstance, we should fix it.
OK, that makes sense.
isinstance(unittest.mock.Mock(), asyncio.Future)
returnsFalse
isinstance(unittest.mock.Mock(asyncio.Future), asyncio.Future)
will return True
.
But isfuture(unittest.mock.Mock(asyncio.Future))
will return False
.
Is that ok?
Oh. Let me see how Mocks work.
But isfuture(unittest.mock.Mock(asyncio.Future)) will return False. Is that ok?
Fixed.