简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM