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 rules
  • strict: 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


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.

Share this post
Follow the RSS feed

Subscribe to the newsletter

Get the latest news about tech new articles and projects.