Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install mypy-lang on python 2.7?

The new version should support 2.7, but pip-installing it fails with a SyntaxError on a line with python 3 type-annotation syntax (which is kinda ironic):

Traceback (most recent call last):
...
from mypy import git
  File "mypy/git.py", line 10
    def is_git_repo(dir: str) -> bool:
                       ^
SyntaxError: invalid syntax
like image 236
Paul Oyster Avatar asked Feb 20 '16 21:02

Paul Oyster


1 Answers

You can't run Mypy on Python 2. The project's README is specific about this:

You need Python 3.2 or later to run mypy.

You can still use it on Python 2 code though. Just use the comment-based annotations and give Mypy the --py2 flag. You also need the typing library for Python 2, which you can install using pip:

pip install typing
like image 58
André Laszlo Avatar answered Oct 11 '22 00:10

André Laszlo