squeaky-pl / japronto

Screaming-fast Python 3.5+ HTTP toolkit integrated with pipelining HTTP server based on uvloop and picohttpparser.
MIT License
8.61k stars 581 forks source link

Cannot use class methods #103

Open stepochkin opened 6 years ago

stepochkin commented 6 years ago

When I add class methods as route handlers:

class TestClass(object):
    async def hello(self, request):
        return request.Response(json=dict(aaa=2))
app = Application()

app.router.add_route('/json2', TestClass().hello)

I get error: TypeError: hello() missing 1 required positional argument: 'request'

Is it possible to use async class methods at all? Or maybe I have done something wrong?

luthfianto commented 6 years ago

I have the same problem too. Looks like when hello is an async method, Japronto won't accept self as the first argument. It only runs correctly when request is the first argument instead of self, which feels wrong