Skip to content
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

Support declaring function signature in a comment #177

Closed
JukkaL opened this issue Jul 3, 2013 · 1 comment
Closed

Support declaring function signature in a comment #177

JukkaL opened this issue Jul 3, 2013 · 1 comment
Labels

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 3, 2013

Make it possible to declare function signature in a comment. This makes is possible to write statically typed code that is valid Python 2. Here is a trivial example:

def inc(x):
    # type: (int) -> int
    return x + 1

Also let the type comment included on the same line as the function header:

def inc(x): # type: (int) -> int
    return x + 1

Methods should not include a type for the self argument:

class A:
    def foo(self, x, y): # type: (int, str) -> None
        pass

Note that this is not good for writing overloaded functions. An alternative syntax, such as using a function decorator, is needed for this (in a separate issue).

@JukkaL
Copy link
Collaborator Author

JukkaL commented Jul 4, 2013

For *args and **kwargs there should be a corresponding * or ** in the signature:

def foo(x, *y): # type: (int, *str) -> None
    ...
def bar(x, **y): # type: (int, **bool) -> None
    ...

Arguments with default values don't need anything special:

def foo(x, y=1): # type: (int, int) -> None
    passs

@JukkaL JukkaL closed this as completed in b1ab723 Jul 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant