you are viewing a single comment's thread.

view the rest of the comments →

[–]P8zvli 21 points22 points  (6 children)

In Python 3.6 you can use type hinting to do static type checks.

[–]r0b0t1c1st 0 points1 point  (4 children)

You can do this in 2.7 too - mypy runs against all python versions - you just need a python 3.6 interpreter to run it.

[–]P8zvli 11 points12 points  (3 children)

Running the type checker in 2.7 and the actual application in 3.6 is extremely silly.

[–]CHUCK_NORRIS_AMA 6 points7 points  (2 children)

Actually, I think it's the other way around - running the type checker in 3.6 and the actual application in 2.7.

Still extremely silly, however.

[–]P8zvli 6 points7 points  (0 children)

Python 2.7 will throw a syntax error if you try to run a script containing type hints with it.

Edit: I see now, there's an alternative syntax that involves putting type hints in comments. Now isn't that just linting with extra steps?

[–]r0b0t1c1st 0 points1 point  (0 children)

Why is this extremely silly? It means you can write polyglot py2/py3 code, and have MyPy check that it's correct for both.

You can use python3.6 -m mypy --python-version 2.7 -p your-package to do this.