How is mypy different from Cython?
Cython is a variant of Python that supportscompilation to CPython C modules. It can give major speedups tocertain classes of programs compared to CPython, and it providesstatic typing (though this is different from mypy). Mypy differs inthe following aspects, among others:
- Cython is much more focused on performance than mypy. Mypy is onlyabout static type checking, and increasing performance is not adirect goal.
- The mypy syntax is arguably simpler and more “Pythonic” (no cdef/cpdef, etc.) for statically typed code.
- The mypy syntax is compatible with Python. Mypy programs are normalPython programs that can be run using any Pythonimplementation. Cython has many incompatible extensions to Pythonsyntax, and Cython programs generally cannot be run without firstcompiling them to CPython extension modules via C. Cython also has apure Python mode, but it seems to support only a subset of Cythonfunctionality, and the syntax is quite verbose.
- Mypy has a different set of type system features. For example, mypyhas genericity (parametric polymorphism), function types andbidirectional type inference, which are not supported byCython. (Cython has fused types that are different but related tomypy generics. Mypy also has a similar feature as an extension ofgenerics.)
- The mypy type checker knows about the static types of many Pythonstdlib modules and can effectively type check code that uses them.
- Cython supports accessing C functions directly and many features aredefined in terms of translating them to C or C++. Mypy just usesPython semantics, and mypy does not deal with accessing C libraryfunctionality.