Hello,

I already opened an issue on Github.

Thanks, but I prefer to stick with the old type syntax
 # type: () -> Dict[str, SQLFORM]

solution instead of creating another function.


Best regards,

João Matos
On 08-03-2019 16:45, Anthony wrote:
In order to determine which functions in a controller file to expose as actions, web2py uses the following regex (the intention is to identify only functions that take no arguments and don't start with a double underscore):

'^def\s+(?P<name>_?[a-zA-Z0-9]\w*)\( *\)\s*:'

As you can see, this does not support type hints. Feel free to open an issue on Github or submit a pull request to allow type hints.

In the meantime, you can create a separate function with the type hint and call that function from within a non-hinted action:

def get_approval():
   
return hinted_get_approval()

Anthony

On Friday, March 8, 2019 at 9:31:58 AM UTC-5, João Matos wrote:

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

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/YtJOP9Bv9ro/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to