mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-01-31 00:54:22 +01:00
Add type information for the first two arguments of all endpoints
This commit is contained in:
parent
52b16e4f4b
commit
5cf181bae6
1 changed files with 13 additions and 0 deletions
|
|
@ -41,6 +41,8 @@ def endpoint(route,
|
|||
|
||||
postprocess=None
|
||||
):
|
||||
from calibre.srv.handler import Context
|
||||
from calibre.srv.http_response import RequestData
|
||||
def annotate(f):
|
||||
f.route = route.rstrip('/') or '/'
|
||||
f.route_key = route_key(f.route)
|
||||
|
|
@ -51,6 +53,17 @@ def annotate(f):
|
|||
f.cache_control = cache_control
|
||||
f.postprocess = postprocess
|
||||
f.is_endpoint = True
|
||||
argspec = inspect.getargspec(f)
|
||||
if len(argspec.args) < 2:
|
||||
raise TypeError('The endpoint %r must take at least two arguments' % f.route)
|
||||
f.__annotations__ = {
|
||||
argspec.args[0]: Context,
|
||||
argspec.args[1]: RequestData,
|
||||
}
|
||||
f.__doc__ = (f.__doc__ or '') + '\n\n' + (
|
||||
(':type %s: calibre.srv.handler.Context\n' % argspec.args[0]) +
|
||||
(':type %s: calibre.srv.http_response.RequestData\n' % argspec.args[1])
|
||||
)
|
||||
return f
|
||||
return annotate
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue