Allow usage of functools.partial async handlers#984
Conversation
|
This is interesting. I would like to be able to use partial functions as handlers as well and didn't know about this bug. Two questions:
def iscoroutinefunction_or_partial(object):
while isinstance(object, functools.partial):
object = object.func
return inspect.iscoroutinefunction(object) |
|
@erewok I think my eyes skipped right over that while statement when I initially read the issue. If this sounds good, I'd like to add the method you pointed out ( |
|
I like those ideas. I would defer to @tomchristie on merging the result. |
|
@erewok I was afraid of this... with the py 3.8 check, we now fall under 100% coverage on that interpreter. Any suggestions? Or should we just dump the check and let the while loop run? |
|
Let's see what @tomchristie thinks about this PR. I'm not sure how he'll want to handle different behavior in different Python versions and don't want to suggest you do a bunch of work. I think the idea is solid overall. |
|
BTW, this is the kind of usage i'm thinking about: I had to write some methods (ie: handle_get, handle_post) that otherwise might not be needed if partials would be possible. |
|
@vladmunteanu You can add a Example in my recent PR: |
|
@kevinastone thanks, I was going to propose that, but I was also curious what @tomchristie has to say about this before. I guess I should just do it to increase my chances. |
|
Hey @erewok , thanks for the approval! |
|
hello @vladmunteanu, sorry for the late reply, but I haven't been available for open source for months due to work obligations. I will check with the encode maintainers this week to see if everyone is okay with releasing this. Thanks again. |
florimondmanca
left a comment
There was a problem hiding this comment.
Just checked out this PR and this looks good to me. :)
|
Thanks everyone for getting this through! |
At the moment, one cannot pass a partial asynchronous handler, because: