[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2019-06-12 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

I guess the inconsistency in original report is fixed with issue28703 where 
both inspect.iscoroutinefunction and asyncio.iscoroutinefunction return False 
for Mock(). The fix is available from 3.5.3 . There is also async support for 
mock added in 3.8 with issue26467. I am closing this as part of triaging. Feel 
free to reopen this if I am missing something. Thanks.

# Python 3.5

python3.5
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> from unittest.mock import *
>>> asyncio.iscoroutinefunction(Mock())


# Master

./python.exe
Python 3.9.0a0 (heads/master:daf6262751, Jun 12 2019, 23:12:37)
[Clang 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from unittest.mock import Mock
>>> import asyncio, inspect
>>> inspect.iscoroutinefunction(Mock())
False
>>> asyncio.iscoroutinefunction(Mock())
False

--
nosy: +xtreak
resolution:  -> fixed
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2016-04-23 Thread Jesús Cea Avión

Changes by Jesús Cea Avión :


--
nosy: +jcea

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-12-22 Thread Guido van Rossum

Guido van Rossum added the comment:

No I just misremembered.

--Guido (mobile)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-12-22 Thread Yury Selivanov

Yury Selivanov added the comment:

> Now we missed the 3.5.2 deadline.

Did you mean 3.5.1?  Or Larry is going to rush 3.5.2 soon?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-12-22 Thread Joseph Gordon

Joseph Gordon added the comment:

I uploaded a patch that appears to fix the issue.

--
keywords: +patch
Added file: http://bugs.python.org/file41396/issue25599.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-12-22 Thread Joseph Gordon

Changes by Joseph Gordon :


--
nosy: +josephgordon

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-12-22 Thread Guido van Rossum

Guido van Rossum added the comment:

Oh dang. We were waiting for the OP to submit a patch (not very complex)
but they never did. Now we missed the 3.5.2 deadline. Maybe someone can try
again for 3.5.3?

On Tue, Dec 22, 2015 at 12:30 AM, Joseph Gordon 
wrote:

>
> Changes by Joseph Gordon :
>
>
> --
> nosy: +josephgordon
>
> ___
> Python tracker 
> 
> ___
>

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-11-12 Thread Guido van Rossum

Guido van Rossum added the comment:

OK, I concede your point. It shouldn't be too hard to make
asyncio.iscoroutinefunction() behave the same way as
inspect.iscoroutinefunction(). Can you submit a patch?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-11-11 Thread Theron Luhn

Theron Luhn added the comment:

For me, the context is a test I was writing that went something like this:

>>> import asyncio
>>> from unittest.mock import Mock
>>> loop = asyncio.get_event_loop()
>>> blocking_func = Mock()
>>> loop.run_in_executor(None, blocking_func)
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/base_events.py",
 line 497, in run_in_executor
raise TypeError("coroutines cannot be used with run_in_executor()")
TypeError: coroutines cannot be used with run_in_executor()

I understand that the nature of Mock makes its behaviors ambiguous.  However, 
there are a few reasons I think asyncio.iscoroutinefunction(Mock()) should be 
false:

1) inspect.iscoroutinefunction reports false.  asyncio.iscoroutinefunction 
should be consistent with this.
2) A coroutine function should return a coroutine object.  Mock's default 
behavior won't return a coroutine object, so it shouldn't be identified as a 
coroutine function by default.
3) It's tidier to make a non-coroutine function Mock into a coroutine function 
(asyncio.coroutine(Mock())) than it is to make a coroutine function Mock into a 
non-coroutine function Mock (mock._is_coroutine is implementation-specific 
hack).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-11-10 Thread Guido van Rossum

Guido van Rossum added the comment:

Hm... I don't know what answer you would expect. Who says your mock shouldn't 
behave like a coroutine? In general, passing mocks to functions is likely to 
return a mock -- even boolean functions.

Can you provide more context?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-11-10 Thread Theron Luhn

New submission from Theron Luhn:

>>> asyncio.iscoroutinefunction(unittest.mock.Mock())


This is an unexpected response, both in type (Mock rather than boolean) and 
value (truthy).

inspect.iscoroutinefunction behaves as expected.

Workaround:

>>> m = unittest.mock.Mock()
>>> m._is_coroutine = False
>>> asyncio.iscoroutinefunction(m)
False

--
components: asyncio
messages: 254457
nosy: Theron Luhn, gvanrossum, haypo, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.iscoroutinefunction returns unexpected results when presented 
with unittest.mock.Mock
type: behavior
versions: Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25599] asyncio.iscoroutinefunction returns unexpected results when presented with unittest.mock.Mock

2015-11-10 Thread STINNER Victor

STINNER Victor added the comment:

>>> asyncio.iscoroutinefunction(unittest.mock.Mock())


Yeah, I already had this issue when I wrote unit tests using mock :-/ I didn't 
find an obvious fix for this issue, and it's quite easy to workaround it.

It looks like the "m._is_coroutine = False" is not used in asyncio tests. I 
don't recall how I worked around the issue in asyncio tests...

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com