pytype
A static type analyzer for Python code
When I usually talk to folks about pytype, they want to know how it compares to mypy.
What do you think are the main advantages of Pytype over Mypy?
How do pytype and mypy compare?
mypy
pytype
Gradual typing and inference
def f():
return "PyCon"
def g():
return f() + 2019
Gradual typing and inference: mypy
def f() -> str:
return "PyCon"
def g() -> int:
return f() + 2019
mypy: 4: error: Unsupported operand types for +
Gradual typing and inference: pytype
def f():
return "PyCon"
def g():
return f() + 2019
pytype: line 4, in g: unsupported operand type(s) for +
Strictness
from typing import List
def get_list() -> List[str]:
lst = ["PyCon"]
lst.append(2019)
return lst
Strictness: mypy
from typing import List
def get_list() -> List[str]:
lst = ["PyCon"] # List[str]
lst.append(2019) # List[str].append(int)
return lst
mypy: 4: error: Argument 1 to "append" of "list" has incompatible type
Strictness: pytype
from typing import List
def get_list() -> List[str]:
lst = ["PyCon"] # List[str]
lst.append(2019) # List[Union[str, int]]
return lst # List[Union[str, int]] != List[str]
pytype: line 5, in get_list: bad option in return type
pytype
A static type analyzer for Python code
Optional static typing for Python