Python in Visual Studio Code – December 2021 Release
We are pleased to announce that the December 2021 release of the Python Extension for Visual Studio Code is now available. You can download the Python extension from the Marketplace, or install it directly from the extension gallery in Visual Studio Code. If you already have the Python extension installed, you can also get the latest update by restarting Visual Studio Code. You can learn more about Python support in Visual Studio Code in the documentation.
This announcement includes:
- Module rename refactoring with change preview, via Pylance
- A rich editing experience when working with virtual or untrusted workspaces
- An update regarding debugging with Python 2.7
- A community highlight: Don Jayamanne’s new Python environment management extension
If you’re interested, you can check the full list of improvements included in this release in our changelog.
Module rename with change preview
One of our most heavily requested features is finally here! As of this release, you can now more easily refactor your code using a new rename refactoring experience, via Pylance.
Previously, when you renamed a file/module, you would have searched for references to that module in your codebase and update each location manually.
As of this release, after renaming a Python file/module, Pylance will find all the instances that need to be updated and provide you with a preview of all the changes to be made. If you want to customize the references to be updated, you can toggle check boxes at the line or file level at the preview stage before accepting the changes. You can also change your mind after seeing what would be changed at the preview stage and discard all changes.
With this preview, you can feel even more confident in the changes that are being made to your code and still save time when refactoring.
Rich Python editing experience when working with virtual or untrusted workspaces
The Python extension now offers syntax error detection and limited IntelliSense support when using virtual or untrusted workspaces via Pylance. Just like when using github.dev or vscode.dev, you can now take advantage of a series of editing features you might want when exploring a codebase virtually, or when inspecting the workspace locally to decide whether you’ll mark it as trusted.
The feature set includes:
- Semantic highlighting
- Completions for built-ins, Pylance’s bundled stubs, locally defined symbols in the current file, and symbols in open files
- Syntax errors
- Code navigation
- Outline support
- Function signature help
- Contextual document highlighting
We’re excited for you to give this new experience a try and welcome any feedback on the Pylance issue tracker.
An update on debugging with Python 2.7
Following up last September’s announcement on limited IntelliSense support for Python 2.7, this is the last release with support for debugging locally with Python 2.7. This is because our debugger, debugpy, will no longer Python 2.7 starting in January 2022.
This change should impact only the local experience, and not remote debugging – attaching the debugger to remote processes running in Python 2.7 will still be supported.
Python Environment Manager extension
You can now inspect your Python environments and its packages with the Python Environment Manager extension! This extension is developed and maintained by Don Jayamanne, a member of our team and the creator of the Python extension. While not an official Microsoft extension, we wanted to give it a shout-out to help spread the word about it!
With the Python environment manager, you can open the manager view and see information on multiple Python environments located on your machine – even virtual environments not located in your workspace. You can then check which packages are installed in that environment as well as their versions.
You can also create multiple terminals for different environments – once you click on the terminal icon next to an environment, it will automatically activate it.
If you have any feedback or feature requests, you can file an issue on the Python environment manager’s GitHub repository.
Other Changes and Enhancements
We would also like to extend special thanks to this month’s contributors:
- Brian Rutledge: Partial fix for using the same directory as discovery when running tests (#9553), –rootdiris no longer interpreted as a test folder when using pytest (#16079), and fix for pytest run all tests when using ini and cwd. (#17546)
- Martijn Pieters: Fix for issue with parsing pytest node ids. (#17676)
- Sorin Sbarnea: Ensure that path towards external tools like linters are not synched between machines. (#18008)
Be sure to download the Python extension for Visual Studio Code now to try out the above improvements. If you run into any problems or have suggestions, please file an issue on the Python VS Code GitHub page.
what theme are you using? it looks pleasing to the eye 🙂
That is Horizon Extended Theme. 😊