[issue23519] using asyncio.iscoroutinefunction() on a functools.partial object

2017-06-08 Thread Guido van Rossum

Guido van Rossum added the comment:

Use a lambda instead of partial. It's more pythonic.

--

___
Python tracker 

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



[issue23519] using asyncio.iscoroutinefunction() on a functools.partial object

2017-06-08 Thread Curt McDowell

Curt McDowell added the comment:

There are use cases for this. I hit the problem and eventually wound up here, 
so I'd like to make a case to re-open.

My project has a callback registry of asyncio handler routines.

register_callback(condition1, handler1)
register_callback(condition2, handler2)
...

I want to register many callbacks, but use only one handler and an argument to 
differentiate it. I realize our callback systems should provide for a cookie, 
but it doesn't. 

register_callback(condition1, functools.partial(handler, 'detail1'))
register_callback(condition2, functools.partial(handler, 'detail2'))

The callback registry makes sure iscoroutinefunction(handler) because we don't 
want to defer error checking to the distant future. But iscoroutinefunction() 
returns False for the partial function. I was hopeful that this might work, but 
alas, no:

register_callback(condition1,
  asyncio.coroutine(functools.partial(handler, 'detail1')))

--
nosy: +curtmcd

___
Python tracker 

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



[issue23519] using asyncio.iscoroutinefunction() on a functools.partial object

2015-02-26 Thread Guido van Rossum

Guido van Rossum added the comment:

Yeah, your "add event handler" routine shouldn't be so picky to insist that 
iscoroutinefunction() returns True. It should just call the thing and verify 
that it has returned a coroutine object (asyncio.iscoroutine()).

--
resolution:  -> not a bug
status: open -> closed

___
Python tracker 

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



[issue23519] using asyncio.iscoroutinefunction() on a functools.partial object

2015-02-26 Thread Mathieu Pasquet

Mathieu Pasquet added the comment:

Using functools.partial with coroutines would be mostly out of convenience, in 
order to avoid having factories in that return parametrized coroutine 
functions. I guess in such cases it might be better to create a two-lines 
wrapper around partial() to make it return a coroutine rather than change the 
stdlib for that.

In the attached file is an example of such use, where EventNotifier is a 
Protocol which receives external events and triggers event handlers based on 
that, and where the add_event_handler function checks if the handler is a 
coroutine function. In which case it uses asyncio.async to schedule the handler 
call; otherwise it uses loop.call_soon.

You can close this, I guess.

--
Added file: http://bugs.python.org/file38246/example_partial.py

___
Python tracker 

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



[issue23519] using asyncio.iscoroutinefunction() on a functools.partial object

2015-02-26 Thread STINNER Victor

STINNER Victor added the comment:

> Plus there is no use case.

Mathieu: can you maybe give some examples? How are you using functools.partial 
with coroutines?

--

___
Python tracker 

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



[issue23519] using asyncio.iscoroutinefunction() on a functools.partial object

2015-02-25 Thread Guido van Rossum

Guido van Rossum added the comment:

I recall discussing this before (maybe on the tulip list). I am firmly against. 
It is a slippery slope -- why inspect a partial but not a lambda? Plus there is 
no use case.

--

___
Python tracker 

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



[issue23519] using asyncio.iscoroutinefunction() on a functools.partial object

2015-02-25 Thread Mathieu Pasquet

New submission from Mathieu Pasquet:

Using iscoroutinefunction() on an object returned by functools.partial() should 
return True if the function wrapped was a coroutine function.

(a recursive loop like the one in asyncio/events.py get_function_source() may 
be what needs to be done)

--
components: asyncio
messages: 236569
nosy: gvanrossum, haypo, mathieui, yselivanov
priority: normal
severity: normal
status: open
title: using asyncio.iscoroutinefunction() on a functools.partial object
type: enhancement
versions: Python 3.4

___
Python tracker 

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