Pay attention please: handler is converted to coroutine internally when it is a regular function.
所以源码中关于fn的判断是不是可以不用加
def add_route(app, fn):
method = getattr(fn, '__method__', None)
path = getattr(fn, '__route__', None)
if path is None or method is None:
raise ValueError('@get or @post not defined in %s.' % str(fn))
if not asyncio.iscoroutinefunction(fn) and not inspect.isgeneratorfunction(fn):
fn = asyncio.coroutine(fn)
logging.info('add route %s %s => %s(%s)' % (method, path, fn.__name__, ', '.join(inspect.signature(fn).parameters.keys())))
app.router.add_route(method, path, RequestHandler(app, fn))
靠谱灬男青年
aiohttp文档中关于
add_route
的一段描述所以源码中关于fn的判断是不是可以不用加