Skip to content

Need a solution for long signatures in Python 2 #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gvanrossum opened this issue Mar 2, 2016 · 4 comments
Closed

Need a solution for long signatures in Python 2 #186

gvanrossum opened this issue Mar 2, 2016 · 4 comments
Milestone

Comments

@gvanrossum
Copy link
Member

See python/mypy#1102. I propose to go with this form:

def whatever(
         arg1,  # type: int 
         arg2,  # type: int
         arg3,  # type: int
         arg4,  # type: str
         arg5,  # type: str
         arg6,  # type: str
         ):
    # type: (...) -> float
    # this is not a type comment (note that "..." above is literal)
    return (arg1 + arg2 + arg3 +
            float(arg4) + float(arg5) + float(arg6))

(We'll keep the other form too, since it is fine for short signatures.)

@vlasovskikh
Copy link
Member

Would it be valid to annotate just a few arguments? Only the return type?

@gvanrossum
Copy link
Member Author

Yes to both. The proposed semantics of # type: (...) -> blah match nicely with that.

In fact it should also be possible to just annotate some arguments and not give the signature at all -- that's like leaving the "-> blah" out from the PY3 form.

However you shouldn't annotate individual arguments and have explicit types in the latter; this is invalid:

def foo(a # type: int
    ):
    # type: (int) -> int
    pass

@gvanrossum gvanrossum added this to the 3.5.2 milestone Mar 18, 2016
@gvanrossum
Copy link
Member Author

Fixed in the PEP by https://hg.python.org/peps/rev/81c177edf735. Implemented in PyCharm (but not yet in mypy).

@gvanrossum
Copy link
Member Author

Also a6e763a in the typing repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants