If I write this function
from typing import Dict
@auth.requires(lambda: (auth.requires_login() and request.env.http_referer
and ('/client' in request.env.http_referer
or '/client/get_approval' in request.env.http_referer)))
def get_approval() -> Dict[str, SQLFORM]:
"""Get approval for deletion.
:return: Dict with form.
"""
rec_id: str = request.args[0]
rows_dic: Dict[int, str] = {**general.get_members(db, SUPERVISOR_ROLE),
**general.get_members(db, MANAGER_ROLE)}
form = SQLFORM.factory(
Field('user_id', label=T('Supervisor/Manager'),
requires=IS_IN_SET(rows_dic, zero=T('Choose one...'))),
Field('password', 'password', label=T('Password'), requires=IS_NOT_EMPTY()),
buttons=[BUTTON(T('Submit'), _type='submit', _class='btn btn-primary')],
formstyle='table3cols',
)
...
return dict(form=form)
web2py shows a web page with the message
invalid function (client/get_approval)
If however I write it without the return type on the
header
from typing import Dict
@auth.requires(lambda: (auth.requires_login() and request.env.http_referer
and ('/client' in request.env.http_referer
or '/client/get_approval' in request.env.http_referer)))
def get_approval():
# type: () -> Dict[str, SQLFORM]
"""Get approval for deletion.
:return: Dict with form.
"""
rec_id: str = request.args[0]
rows_dic: Dict[int, str] = {**general.get_members(db, SUPERVISOR_ROLE),
**general.get_members(db, MANAGER_ROLE)}
form = SQLFORM.factory(
Field('user_id', label=T('Supervisor/Manager'),
requires=IS_IN_SET(rows_dic, zero=T('Choose one...'))),
Field('password', 'password', label=T('Password'), requires=IS_NOT_EMPTY()),
buttons=[BUTTON(T('Submit'), _type='submit', _class='btn btn-primary')],
formstyle='table3cols',
)
...
return dict(form=form)
it all works.
I even tried with just -> Dict to see if it was a
problem with SQLFORM, but it returns the same message.
Windows 7 Pro x64 SP1+all updates
Firefox 65.0.2 x64
Python 3.7.1 x86
web2py 2.18.3