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
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.
How to manage Internationalization with NextJS SSG
Staticaly generating a website with the NextJS framework in different languages is not so obvious.
Install and configure a DNS server with Bind9 on Linux
A service DNS (Domain Name Service) allows domain name resolution to an IP Address and other resources. This service is useful for example for browsing internet websites and not have to know IPs addresses for these websites.