头图

We're excited to announce that the August 2022 Python and Jupyter extensions for Visual Studio Code are now available!

This release includes the following improvements:

• Automatic debug configuration for web applications • Improvements to the onboarding experience • Settings related to displaying interpreter information on the status bar • A new Python tool extension template • Use Pylance to remove unused imported modules • Double click to accept Pylance type hints • Copy output image in Jupyter cell Quickly jump to the most recent failed cell

If you're interested, you can see the full list of improvements to Python , Jupyter , and Pylance extensions in our changelog.

Automatic debugging configuration for web applications

To simplify the process of setting up VS Code to run or debug web applications, this release includes a new automatic debugging configuration for projects using 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 in the workspace (i.e. no launch.json file), you will see "show all automatic debug configurations" option. If your project is a web application that follows the expected format of Flask, Django, or FastAPI, after clicking this option, you will be able to see the debug configuration dynamically created for executing and debugging the project. Now you can just select it and start catching all bugs!

1
Subject: Pink-Cat-Book

Improvements to the onboarding experience

The Python extension has been improved to make it easier to guide users to install and select a specific version of Python when needed. If Python is not installed on your Windows computer, selecting the "Install Python" button in the walkthrough will open the Python application in the Microsoft Store. Meanwhile, if on Linux or macOS, Terminal will automatically run and display installation instructions.

Another improvement related to the onboarding experience is that the notification to choose an interpreter is now only shown when an interpreter is required (for example, when running or debugging a file, or when using tools such as a linter or formatter), and is no longer displayed on startup. Other notification prompts have also been improved to more accurately display errors and suggested changes.

The Python interpreter is displayed on the status bar

We have 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 it in the user settings (Preferences > Command Palette… > Open User Settings (JSON)) to always show it no matter what file is open. By default it is only shown when Python related files are open in the editor ( "python.interpreter.infoVisibility": "onPythonRelated" ). If you want to hide it completely, set
"python.interpreter.infoVisibility": "never"

A warning status has also been added to indicate cases where the selected interpreter is invalid:

Python tool extension template

Based on what we've been doing to enable formatting and linting of Black , pylint , and isort to work behind the Language Server Protocol, we realized that we could more simply create extensions for most Python linter or formatters without TypeScript (This is written in the language within VS Code and its extensions).

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 most of your Python code (unless you plan to add more settings or custom logic to it) - then you will need to use some TypeScript).

To try it out, you can follow the instructions in the repository . If you want to publish your new extension (and maintain it, after all, with great power comes great responsibility), you can follow the steps in the "Publishing Extensions" documentation .

If you have any feedback on this new template, please raise an issue on the GitHub repository !

remove all unused imports

Pylance now provides a code action to remove all unused imports at once if there are multiple imported libraries that are not used or called in the code. To try it out, open a Python file containing unused imported modules and trigger a code action called "Remove all unused imports":


Subject: Pink-Cat-Book

You can also configure VS Code to run all available "fix all" code actions when saving a Python file by adding the following to your user settings:

 "[python]": {
    "editor.codeActionsOnSave": {
        "source.fixAll": true
    }
}

Double tap to accept type hints

In the July release , we added support for variable type and return type embedding hints when using Pylance . In this release, we will support accepting suggested code comments. You can now double click on the prompt to add the suggestion to your code:

To learn more about Inlay type hints and some tips on how to best utilize this feature, check out Jay Miller's explanatory video and blog post on "Making Inlay Type Hints in Python appear/disappear" .

Copy images from Jupyter Notebooks to clipboard

A new version of the Jupyter extension allows you to copy images from Jupyter Notebook output cells to the clipboard so you can share them outside of VS Code more easily!

If you want to try it out, make sure to change the output presentation to png by clicking the icon to the left of the image you want to copy:

image.png

Then hover over the image and select the copy button shown on the right:

image.png

Now you can paste it into your emails, documents, reports and even drawings !

Go to the most recently failed cell

Another improvement introduced in the latest Jupyter extension version is the ability to navigate to the most recently failed cell. When you run all cells and one of them fails, you can click the "Go To" button at the top of the editor and you will jump to the cell that failed the run.

Other changes and enhancements

We've also added some small enhancements and user-requested fixes that should improve your experience with Python and Jupyter Notebooks in Visual Studio Code. Some notable changes include:

• There is a new setting in the Pylint and Black extensions that allows you to specify an interpreter command to start 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 interactive windows when using Pylance ( pylance-release#2894 ).
• Pylance improves type analysis performance ( pylance-release#2881 ).
• Jupyter extensions now have diagnostic messages containing code operations on files that may interfere with Python kernel execution ( vscode-jupyter#10924 ).
• Reloading across VS Code windows can now be resumed by turning on settings resume reloading of interactive windows ( vscode-jupyter#6420 ).

We would also particularly like to thank 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 testing with invalid debug configuration ( vscode-python#19436 ).
BlueskyFR : Remove Gym stubs ( vscode-python#218 ).

Try these new improvements by downloading the Python extension and 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 Visual Studio Code Python in the documentation . If you run into any issues or have suggestions, please file an issue on the Python VS Code GitHub page.

Welcome to the official Python in Visual Studio Code site to learn more.
image.png

Click to go to the official document~


微软技术栈
423 声望997 粉丝

微软技术生态官方平台。予力众生,成就不凡!微软致力于用技术改变世界,助力企业实现数字化转型。