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

adding static type checking via mypy #79

Closed
1 task
rasbt opened this issue Jul 29, 2016 · 0 comments
Closed
1 task

adding static type checking via mypy #79

rasbt opened this issue Jul 29, 2016 · 0 comments

Comments

@rasbt
Copy link
Owner

rasbt commented Jul 29, 2016

Add type hints (see PEP484) and static type checking to Travis CI using mypy.

  • however, the question is whether we want to use the full type-hinting syntax (and maybe lose compatibility with older python versions) or just the type-hinting via comments. e.g.,
def hello(r: int, c=5) -> str:
   s = 'hello'  # type: str
   return '(%d + %d) times %s' % (r, c, s)

vs.

def hello(r, c=5):
   s = 'hello'  # type: str
   return '(%d + %d) times %s' % (r, c, s)

Any thoughts?

UPDATE:

As Daniel Moisset from machinalis pointed out, a Python 2.x compatible alternative to the first scenario above would be:

def hello(r, c=5):
    # type: (int, int) -> str
    """Some docstring"""
    s = 'hello'
    return '(%d + %d) times %s' % (r, c, s)

or for longer parameter lists:

def hello(r,  # type: int
          c=5):
    # type: (...) -> str
    s = 'hello'
    return '(%d + %d) times %s' % (r, c, s)

which would be the best option for now imho.

Also see his awesome blog post for more info on using mypy: http://www.machinalis.com/blog/a-day-with-mypy-part-1/

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

No branches or pull requests

1 participant