-
Notifications
You must be signed in to change notification settings - Fork 5
Python Type Hints
Python type hints are a way to annotate the types of variables, parameters, function arguments, and return values in Python code. They can be used to improve the documentation, linting, compatibility, and performance of your code.
Type hints can help to improve the documentation of your code by making it clear to other developers what types of data are expected and returned by your functions and methods. This can make it easier for other developers to understand how to use your code and to avoid making mistakes.
Type hints can be used by linters to identify potential errors in your code, such as passing the wrong type of data to a function or method. This can help you to catch errors early on, before they cause problems in production.
Type hints can help to reduce the number of runtime errors in your code by catching errors at compile time. This can improve the performance of your code by reducing the number of times that it has to be interpreted or compiled.
Overall, type hints can be a valuable tool for improving the quality, documentation, compatibility, and performance of your Python code. I would encourage you to consider using type hints.
-
Python Typing module
- To annotate the variables and method/function return types
-
Mypy
- To check the static typings of the variables and method/function return types
-
beartype
- To check runtime types. This package essentially adds a layer of protection for the user that if they pass in a wrong variable type to a function, it will immediately catch it and give an error to the user making it easier to debug what went wrong.
We also have a mypy CI check that runs mypy and catches any possible errors during PRs