We’re excited to announce that the August 2022 release of the Python and Jupyter extensions for Visual Studio Code are now available!
This release includes the following improvements:
- Automatic debug configurations for web apps
- Improvements to the Getting Started Experience
- Setting to configure the display of the interpreter information on the status bar
- A new Python Tools extension template
- Remove all unused imports with Pylance
- Double click to accept type hints with Pylance
- Copy output image in Jupyter cells
- Go to most recently failed cell
If you’re interested, you can check the full list of improvements in our changelogs for the Python, Jupyter and Pylance extensions.
Automatic debug configurations for web apps
To simplify the process of setting up VS Code to run and/or debug your web applications, this release includes new automatic debug configurations for projects that use Flask, Django or FastAPI.
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 launch.json file) on your workspace, you will see an “show all automatic debug configurations” option. If your project is a web application that follows the format expected by Flask, Django or FastAPI, once you click on that option you will be able to see debug configurations that were dynamically created to execute and debug your project. Now you can just select it to start catching all the bugs!
Theme: Pink-Cat-Book
Improvements to the Getting Started Experience
The Python extension walkthrough has been improved to more easily guide users to installing Python when needed, and selecting it in VS Code. When Python is not installed on a Windows machine, selecting the “Install Python” button from the walkthrough will open the Python app in the Microsoft Store. When on Linux or macOS, the displayed installation instructions will be automatically run in the terminal.
Another improvement related to the getting started experience is that notifications for selecting the interpreter 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 start-up. Other notification prompts have also been improved to be more precise about errors and suggested changes.
Python interpreter display on the status bar
We introduced a new User setting called “python.interpreter.infoVisibility”
, which controls when the selected interpreter information is displayed in the status bar. You can set "python.interpreter.infoVisibility": “always”
on your User settings (Preferences > Command Palette… > Open User Settings (JSON)) to always display it regardless of what file is opened. By default, it’s only displayed when Python-related files are open on the editor ("python.interpreter.infoVisibility": “onPythonRelated”
). If you’d like to hide it completely, set "python.interpreter.infoVisibility": “never”
.
A warning status was also added to indicate situations when the selected interpreter is invalid:
Python Tools extension template
With all the work we have been doing to enable formatting and linting with Black, pylint, and isort to work behind the Language Server Protocol, we realized how simple we could make it to create an extension for mostly any Python linter or formatter without the need to require TypeScript knowledge (which is the language VS Code and its extensions are written in).
To that end, our team has created a template that allows you to create a VS Code extension for your favorite Python linter or formatter by changing mostly Python code (unless you’re planning to add more settings or custom logic to it – then you’ll need to work with a bit of TypeScript).
To try it out, you can follow the instructions in the repository. If at the end you’d like to publish your new extension (and maintain it, after all with great power comes great responsibility), you can follow the steps on the “Publishing Extensions” documentation.
And If you have any feedback on this new template, please file an issue on the GitHub repo!
Remove all unused imports
Pylance now offers a code action for removing all unused imports when there is more than one library that is being imported but not used or called anywhere in the code. To try it out, open a Python file with such statements and trigger the code action called “Remove all unused imports”: Theme: Pink-Cat-Book
You can also configure VS Code to run all available “fix all” code actions when you save your Python files by adding the following configuration to your User settings:
"[python]": { "editor.codeActionsOnSave": { "source.fixAll": true } }
Double click to accept Type Hints
In the July release, we have added support for variable types and return types inlay hints when using Pylance. In this release, we’re introducing support to accepting the suggested annotations to your code. You can now double click on a hint to add the suggestion to your code:
To learn more about Inlay Type hints and for some tips on how you can best leverage this feature, check out Jay Miller’s explanatory video and blog post on how to “Make Inlay Type Hints in Python Appear/Disappear”.
Copy images to clipboard from Jupyter Notebooks
The new release of the Jupyter extension allows you to copy images from Jupyter notebooks output cells to the clipboard so you can more easily share them outside of VS Code!
To try it out, make sure you change the output presentation to png, by clicking on the icon on the left side of the image you’re trying to copy:
Then hover over the image and select the copy button that shows up to the right:
And now you can paste it into your e-mails, documents, reports and even Paint!
Go to most recently failed cell
Another improvement introduced in the latest Jupyter extension release is the ability to navigate to the most recently failed cell. When you run all your cells and one fails, you can click on the “Go To” button on the top of the editor and you will be taken to the one that halted the group execution.
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:
- There’s a new setting in the Pylint and Black extensions that allow you to specify a interpreter command to launch the LSP server (vscode-python#19303).
- We now have a new command (python.triggerEnvSelection) that other extensions can use to trigger an error notification to select a valid Python interpreter (vscode-python#19450).
- We improved support for magic commands in the interactive window when using Pylance (pylance-release#2894).
- Type analysis performance has been improved with Pylance(pylance-release#2881).
- The Jupyter extension now has diagnostic messages with code actions for files that could interfere with execution of Python Kernels (vscode-jupyter#10924).
- Interactive Window sessions can now be restored across VS Code window reloads by turning on the setting restore (vscode-jupyter#6420).
We would also like to extend special thanks to this month’s contributors:
- dazfuller: Add support for unittest top-level directory option (vscode-python#19398).
- Lakshmikanth2001: Fix URLs in changelog (vscode-python#19414).
- scottshambaugh: Improve error message when using invalid debug configuration for tests (vscode-python#19436).
- BlueskyFR: Remove Gym stubs (vscode-python#218).
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.
The post Python in Visual Studio Code – August 2022 Release appeared first on Python.