3 ms·
That PEP has a section titled "Suggested syntax for Python 2.7 and straddling code", https://www.python.org/dev/peps/pep-0484/#suggested-syntax-for-python-2-7-a
by eesmith 9y ago
That PEP has a section titled "Suggested syntax for Python 2.7 and straddling code", https://www.python.org/dev/peps/pep-0484/#suggested-syntax-for-python-2-7-and-straddling-code https://www.python.org/dev/peps/pep-0484/#suggested-syntax-f...
> Some tools may want to support type annotations in code that must be compatible with Python 2.7. For this purpose this PEP has a suggested (but not mandatory) extension where function annotations are placed in a # type: comment.
mypy supports those annotations for Python 2 code. Quoting http://mypy.readthedocs.io/en/latest/faq.html#how-do-i-type-check-my-python-2-code http://mypy.readthedocs.io/en/latest/faq.html#how-do-i-type-... :
> How do I type check my Python 2 code?
> You can use a comment-based function annotation syntax and use the --py2 command-line option to type check your Python 2 code. You’ll also need to install typing for Python 2 via pip install typing.
- epage 9y agoI fully endorse this. We've been using mypy on our Python2/Python3 project successfully. it is helpful for the type checking but I'm most interested in giving good data to IDEs for code completion.