Basedmypy is a Python type checker that is built on top of the work done by the mypy project. It resolves fundamental issues, limitations and compromises that exist within Mypy and Python's type system.
Based features include:
- Typesafe by default (optional and dynamic typing still supported)
- Baseline functionality
- Support for
Intersection
types - Default return type of
None
instead ofAny
- Generic
TypeVar
bounds - Based type-guards
- Infer parameter type from default value
- Infer overload types
- Bare literals
- Tuple literal types
See the the docs for a comprehensive list.
Also, take a look at BasedPyright, a based type checker and language server based on Pyright!
Basedmypy is installed as an alternative to, and in place of, the mypy
installation:
mypy test.py
python -m mypy test.py
basedmypy was created to attempt to resolve two issues within Python and Mypy's typing ecosystem and to demonstrate new typing concepts:
- Mypy is lacking numerous pieces of functionality
- Pythons type system is full of deeply concerning compromises
You can find a comprehensive list of features in the docs.
If you are using vscode, we recommend the mypy extension
If you are using IntelliJ IDEA/PyCharm, we recommend the basedtyping plugin
If you are using Pydantic, we recommend pydantic-basedtyping
Basedmypy supports a feature called baseline. It allows you to adopt new strictness or features without the burden of refactoring and fixing every new error, just save all current errors to the baseline file and resolve them at what ever pace you want. Only new code will report new errors.
Read more and see examples in the docs