Python in Visual Studio Code improves the “get started” experience — Visual Studio Magazine


Python in Visual Studio Code improves the “get started” experience

Microsoft’s development team for Python in Visual Studio Code has eased the “getting started” experience for its core extension along with many other improvements in the regular monthly update, this for August 2022.

The team, in addition to the core VS Code Marketplace Python extension, also develops and maintains the related Jupyter extension. This main tool is a resounding success as it approaches 62 million installations. That’s way ahead of the second most popular item with 42.7 million installs, which happens to be the Jupyter tool. The second most popular extension is also associated with Python, the Pylance language server (35.2 million).

But it is the main Python tool whose startup experience has been improved.

“The Python extension walkthrough has been improved to more easily guide users through installing Python when needed and selecting it in VS Code,” the team’s Kartik Raj said in a post. August 4 blog post. “When Python is not installed on a Windows machine, selecting the “Install Python” button in the walkthrough will open the Python app in the Microsoft Store. On Linux or macOS, the displayed installation instructions will automatically run in the terminal.

“Another improvement related to the startup experience is that interpreter selection notifications are now only shown when an interpreter is required (e.g. when running or debugging a file, or ‘a tool such as a linter or formatter), and no longer on startup -up. Other notification prompts have also been improved to be more specific about errors and suggested changes.”

Auto debug configurations for web applications
The update also includes new automatic debugging configurations for projects using Flask, Django, or FastAPI, all web frameworks written with Python.

Quick setup of API debugging in an animated action
[Click on image for larger, animated GIF view.] Quick setup of API debugging in an animated action (source: Microsoft).

“When you open the Run and Debug view in VS Code (Ctrl+Shift+D or ⌘+⇧+D) and there is no debugger configuration (i.e., no file launch.json) on your workspace, you will see a ‘show all auto debug configurations’ option,” Raj said. “If your project is a web application that follows the format expected by Flask, Django, or FastAPI , once you click this option, you will be able to see the debug configurations that have been dynamically created to run and debug your project. Now you can just select to start catching all the bugs!”

Other improvements include:

  • Parameter to configure the display of interpreter information on the status bar: A new user setting called “python.interpreter.infoVisibility” controls when information for the selected interpreter is displayed in the status bar. Developers can set “python.interpreter.infoVisibility”: “always” under User Settings to always show information regardless of which file is open. By default, however, it is only shown when Python-related files are opened in the editor (“python.interpreter.infoVisibility”: “onPythonRelated”).
  • A new Python Tools extension model: The team has provided a template to help developers create a VS Code extension for their favorite Python linter or formatter by mostly modifying the Python code, although some TypeScript work is required if other parameters or custom logic is added.
  • Delete all unused imports with Pylance: Developers can now use a code action to remove all unused imports when multiple libraries are imported but are not used or called anywhere in the code.
  • Double-click to accept type hints with Pylance: This builds on previous work to add support for variable types and flags for embedding return types when using the Pylance extension. Here, the team added support for accepting suggested annotations to code, so coders can now double-click a hint to add the suggestion to their code.
  • Copy the output image to Jupyter cells: Developers can now copy output cell images from Jupyter notebooks to the clipboard so they can more easily share them outside of VS Code.
  • Go to the last failed cell: “Another enhancement introduced in the latest version of the Jupyter extension is the ability to navigate to the last failed cell. When you run all your cells and one fails, you can click the “Go To” button at the top from the editor and you will be taken to whoever stopped the execution of the group.”

The announcement post also lists many other changes and improvements.

About the Author

David Ramel is an editor and writer for Converge360.

Briana R. Cross