How to enable Python type checking in VSCode
Emmanuel Gautier / August 18, 2021
2 min read
Since version 3.5, Python now has support for type hints. This typing is a cool new feature allowing type checking across your code for more quality and also help when you are using some packages or call some functions your colleague did in a large codebase. In this article, we will see how to enable type IntelliSense and type checking analysis in Visual Studio Code editor.
First of all, you need to install the Microsoft extension Pylance. This extension provides a set of useful features powered with Pyright, the Microsoft static type checking tool.
With the extension installed and enabled, you should now have better IntelliSense with typing information when you are calling some package function for example. For the type checking analysis, it is not enabled by default, you need to configure it by yourself.
In your settings.json
file, add a new line with the following setting:
{
"python.analysis.typeCheckingMode": "basic"
}
The default value for this line is off
meaning the static analysis is disabled. You have two other possible values which are:
basic
: basic type checking rulesstrict
: All type checking rules at the highest error severity
If you test on the code below you should have a type error in VSCode now
# Wrong type between expected return type and the value type really returned by this function
def wrong_return_type() -> str:
return False
Consulting
If you're seeking solutions to a problem or need expert advice, I'm here to help! Don't hesitate to book a call with me for a consulting session. Let's discuss your situation and find the best solution together.
Featured Posts
Introducing new blog on OAuth, OpenID Connect, and IAM Solutions
I'm excited to announce the launch of a new blog named CerberAuth, where I'll be exploring the world of OAuth, OpenID Connect, and IAM solutions for modern security.
MySQL Docker Image for Mac ARM M1
MySQL official Docker image is not available for Apple ARM-based M1 and M2 CPUs. But there is some options to use mysql image on Mac and more globally on ARMv8 microarchitecture.
How to deal with Docker Hub rate limit on AWS
Since 2020, DockerHub has been limited to only 200 container image pull requests per six hours. This article will help you to deal with this limitation on AWS.