Skip to content

Type comments should be supported #7

Description

@smarie

According to PEP484 one can declare type hints using a "comments" format.

It would be good that create_function supports this way of defining the type hints:

func_signature = """
foo(b,      # type: int
    a = 0,  # type: float
    ):
    # type: (...) -> str
"""

def dummy_handler(*args, **kwargs):
    return "hello"

dynamic_fun = create_function(func_signature, dummy_handler)

assert dynamic_fun.__annotations__ == {'a': float, 'b': int, 'return': str}

Activity

  1. smarie commented on Jan 31, 2019

    @smarie
    OwnerAuthor

    We can support the format, but unfortunately we will not be able to provide the correct __annotations__.

    Indeed, even inspect.signature is not able to capture this:

    def bar(a  # type: int
            ):
        # type: (...) -> float
        return str(a)
    
    s = signature(bar)
    assert s.parameters['a'].annotation is int  # <- FAILS !!!
    assert s.return_annotation is float         # <- FAILS !!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions