Python in Visual Studio Code – March 2024 Release

Courtney Webster

We’re excited to announce the March 2024 release of the Python and Jupyter extensions for Visual Studio Code!

This release includes the following announcements:

  • New Add Imports Code Action heuristics setting
  • Automatically start your browser when debugging Django or Flask apps
  • Shell integration for the Python REPL
  • Language support for locally running Jupyter servers

If you’re interested, you can check the full list of improvements in our changelogs for the Python, Jupyter and Pylance extensions.

New Add Imports Code Action heuristics setting

The Add Import Quick Fix (💡) , triggered when there are missing imports in your Python project, has been improved in the pre-release version of the Pylance extension! Pylance now uses heuristics to show only the top 3 high-confidence import options, prioritized based on: most recently used imports, symbols from the same module, symbols from the standard library, symbols from user modules, symbols from third-party packages, and finally sorting by module and symbol name. In the case where the 3 high-confidence import options aren’t what you are looking for, Pylance introduced a new Code Action, Search for additional import matches, which displays a quick pick menu that allows you to search for import options that prefix-match the missing import symbol.

Pylance Quick Fix and Code Actions for missing imports.

Additionally, Pylance introduced the Change spelling Code Action, which offers import suggestions for missing imports due to typos.

Fix code spelling Code Action with Pylance.

 

We plan to enable this new behavior by default soon. However in the meantime, you can enable it now by setting python.analysis.addImport.heuristics : "true" in your settings.

Automatically start your browser when debugging Django or Flask apps

Developing and testing your Python web applications is now more convenient with the Python Debugger extension! You can now get the browser to automatically open when starting the debugger with Django or Flask apps, by setting autoStartBrowser: true in your launch.json configuration:

{
    "name": "Python Debugger: Flask",
    "type": "debugpy",
    "request": "launch",
    "module": "flask",
    "env": {
        "FLASK_APP": "hello_app.webapp",
        "FLASK_DEBUG": "1"
    },
    "args": [
        "run"
    ],
    "jinja": true,
    "autoStartBrowser": true
}

Auto start browser for web apps using the Python debugger extension.

Shell integration for the Python REPL

We now have shell integration for Python REPL enabled on Mac, Linux and Windows (when using the WSL extension). When executing commands in the Python REPL, colored circle decorators will indicate whether the commands succeeded or failed. This also enables support for the Terminal: Run Recent Command command, allowing you to view and utilize the REPL’s command history. Additionally, this feature allows access to Python’s shell file history for all operating systems via Terminal: Run Recent Command.

Shell integration support for the Python REPL.

Language support for locally running Jupyter servers

Previously, when connecting to local Jupyter servers, the Jupyter extension treated these servers as remote, and as a result the Pylance extension was unable to detect the installed packages. In this iteration, we made changes so that the Jupyter extension detects whether the connected Jupyter server is local or remote, and as a result Pylance is now able to provide richer language features based on packages installed within a local Python environment.

Other Changes and Enhancements

We have also added small enhancements and fixed issues requested by users that should improve your experience working with Python and Jupyter Notebooks in Visual Studio Code. Some notable changes include:

We would also like to extend special thanks to this month’s contributors:

Call for Community Feedback

As we are planning and prioritizing future work, we value your feedback! Below are a few issues we would love feedback on:

Try out these new improvements by downloading the Python extension and the Jupyter extension from the Marketplace, or install them directly from the extensions view in Visual Studio Code (Ctrl + Shift + X or ⌘ + ⇧ + X). You can learn more about Python support in Visual Studio Code in the documentation. If you run into any problems or have suggestions, please file an issue on the Python VS Code GitHub page.

1 comment

Leave a comment

Feedback usabilla icon