{"id":9956,"date":"2024-12-11T12:34:39","date_gmt":"2024-12-11T20:34:39","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/python\/?p=9956"},"modified":"2024-12-16T09:12:17","modified_gmt":"2024-12-16T17:12:17","slug":"python-in-visual-studio-code-december-2024-release","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/python\/python-in-visual-studio-code-december-2024-release\/","title":{"rendered":"Python in Visual Studio Code &#8211; December 2024 Release"},"content":{"rendered":"<p>We&#8217;re excited to announce the December 2024 release of the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-python.python\">Python<\/a>, <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-python.vscode-pylance\">Pylance<\/a> and <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-toolsai.jupyter\">Jupyter<\/a> extensions for Visual Studio Code!<\/p>\n<p>This release includes the following announcements:<\/p>\n<ul>\n<li>Docstring generation features using Pylance and Copilot<\/li>\n<li>Python Environments extension in preview<\/li>\n<li>Pylance &#8220;full&#8221; language server mode<\/li>\n<\/ul>\n<p>If you&#8217;re interested, you can check the full list of improvements in our changelogs for the <a href=\"https:\/\/github.com\/microsoft\/vscode-python\/releases\">Python<\/a>, <a href=\"https:\/\/code.visualstudio.com\/updates\/\">Jupyter<\/a> and <a href=\"https:\/\/github.com\/microsoft\/pylance-release\/blob\/main\/CHANGELOG.md\">Pylance<\/a> extensions.<\/p>\n<h2>Docstring generation using Pylance and Copilot<\/h2>\n<p>A docstring is a string literal that appears right after the definition of a function, method, class, or module used to document the purpose and usage of the code it describes. Docstrings are essential for understanding and maintaining code, as they provide a clear explanation of what the code does, including parameters and return values. Writing docstrings manually can be time-consuming and prone to inconsistencies, however automating this process can ensure your code is well-documented, making it easier for others, and yourself, to understand and maintain. Automated docstring generation can also help enforce documentation standards across your codebase.<\/p>\n<h3>How to enable docstring generation<\/h3>\n<p>To start, open the Command Palette (<code>Ctrl+Shift+P<\/code> (Windows\/Linux) or <code>Cmd+Shift+P<\/code> (macOS)) and select <strong>Preferences: Open Settings (JSON)<\/strong>.<\/p>\n<p>Add the following <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-python.vscode-pylance\">Pylance<\/a> setting to enable support for generating docstring templates automatically within VS Code:<\/p>\n<pre><code class=\"language-json\">  \"python.analysis.supportDocstringTemplate\": true<\/code><\/pre>\n<p>Add the following settings to enable generation with AI code actions:<\/p>\n<pre><code class=\"language-json\">    \"python.analysis.aiCodeActions\": {\r\n        \"generateDocstring\": true\r\n    }<\/code><\/pre>\n<h3>Triggering docstring templates<\/h3>\n<ol>\n<li><strong>Define Your Function or Method<\/strong>:\n<pre><code class=\"language-python\">def my_function(param1: int, param2: str) -&gt; bool:\r\n    pass<\/code><\/pre>\n<\/li>\n<li><strong>Add an Empty Docstring<\/strong>:\n<ul>\n<li>Directly below the function definition, add triple quotes for a docstring.\n<pre><code class=\"language-python\">def my_function(param1: int, param2: str) -&gt; bool:\r\n\"\"\"\"\"\"\r\npass<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>Place the Cursor Inside the Docstring<\/strong>:\n<ul>\n<li>Place your cursor between the triple quotes.\n<pre><code class=\"language-python\">def my_function(param1: int, param2: str) -&gt; bool:\r\n\"\"\"|  # Place cursor here \"\"\"\r\npass<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>When using Pylance, there are different ways you can request that docstrings templates are added to your code.<\/p>\n<h3>Using IntelliSense Completion<\/h3>\n<ol>\n<li>\n<ul>\n<li>Press <code>Ctrl+Space<\/code> (Windows\/Linux) or <code>Cmd+Space<\/code> (macOS) to trigger IntelliSense completion suggestions.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>Using Code Actions<\/h3>\n<ol>\n<li><strong>Open the Context Menu<\/strong>:\n<ul>\n<li>Right-click inside the docstring or press <code>Ctrl+.<\/code> (Windows\/Linux) or <code>Cmd+.<\/code> (macOS).<\/li>\n<\/ul>\n<\/li>\n<li><strong>Select Generate Docstring<\/strong>:\n<ul>\n<li>From the context menu, select <strong>Generate Docstring<\/strong>.<\/li>\n<li>Pylance will suggest a docstring template based on the function signature.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>Using Code Actions to Generate Docstring with Copilot<\/h3>\n<ol>\n<li><strong>Select Generate Docstring With Copilot<\/strong>:\n<ul>\n<li>From the context menu, select <strong>Generate Docstring With Copilot<\/strong>.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Accept Suggestions<\/strong>:\n<ul>\n<li>GitHub Copilot chat will appear. Press <strong>Accept<\/strong> to take the suggestions or continue to iterate with Copilot.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2>Python Environments extension in preview<\/h2>\n<p>We&#8217;re excited to introduce the new <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-python.vscode-python-envs\">Python Environments extension<\/a>, now available in preview on the Marketplace.<\/p>\n<p>This extension simplifies Python environment management with an Environments view accessible via the VS Code Activity Bar. Here you can create, delete, and switch between environments, and manage packages within the selected environment. It also uniquely supports specifying environments for specific files or entire Python projects, including multi-root and mono-repo scenarios.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2024\/12\/updated-envs.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-9966\" src=\"https:\/\/devblogs.microsoft.com\/python\/wp-content\/uploads\/sites\/12\/2024\/12\/updated-envs.gif\" alt=\"Gif showing the Python environments extension managing environments for a multiroot project structure and managing packages in various environments.\" width=\"1228\" height=\"753\" \/><\/a><\/p>\n<p>By default, the extension uses the <code>venv<\/code> environment manager and <code>pip<\/code> package manager to determine how environments and packages are handled. You can customize these defaults by setting <code>python-envs.defaultEnvManager<\/code> and <code>python-envs.defaultPackageManager<\/code> to your preferred environment and package managers. Furthermore, if you have <code>uv<\/code> installed the extension will use it for quick and efficient environment creation and package installation.<\/p>\n<p>Designed to integrate seamlessly with your preferred environment managers via <a href=\"https:\/\/github.com\/microsoft\/vscode-python-environments?tab=readme-ov-file#api-reference-proposed\">various APIs<\/a>, it supports Global Python interpreters, venv, and Conda out of the box. Developers can build extensions to add support for their favorite Python environment managers and integrate with our extension UI, enhancing functionality and user experience.<\/p>\n<p>This extension is poised to eventually replace the environment functionality in the main Python extension and will be installed alongside it by default. In the meantime, you can download the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-python.vscode-python-envs\">Python Environments extensions from the Marketplace<\/a> and use it in <strong>VS Code &#8211; Insiders (<code>v1.96<\/code> or greater) and with the pre-release version of the Python extension (<code>v2024.23<\/code> or greater)<\/strong>. We are looking forward to hearing your feedback on improvements by opening issues in the <a href=\"https:\/\/github.com\/microsoft\/vscode-python-environments\/issues\">vscode-python-environments<\/a> repository.<\/p>\n<h2>Pylance &#8220;full&#8221; language server mode<\/h2>\n<p>The <code>python.analysis.languageServerMode<\/code> setting now supports <code>full<\/code> mode, allowing you to take advantage of the complete range of Pylance&#8217;s functionality and the most comprehensive IntelliSense experience. It&#8217;s worth noting that this comes at the cost of lower performance, as it can cause Pylance to be resource-intensive, particularly in large codebases.<\/p>\n<p>The <code>python.analysis.languageServerMode<\/code> setting now changes the default values of the following settings, depending on whether it&#8217;s set to <code>light<\/code>, <code>default<\/code> or <code>full<\/code>:<\/p>\n<table>\n<thead>\n<tr>\n<th>Setting<\/th>\n<th>light<\/th>\n<th>default<\/th>\n<th>full<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>python.analysis.exclude<\/td>\n<td>[&#8220;**&#8221;]<\/td>\n<td>[]<\/td>\n<td>[]<\/td>\n<\/tr>\n<tr>\n<td>python.analysis.useLibraryCodeForTypes<\/td>\n<td>false<\/td>\n<td>true<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>python.analysis.enablePytestSupport<\/td>\n<td>false<\/td>\n<td>true<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>python.analysis.indexing<\/td>\n<td>false<\/td>\n<td>true<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>python.analysis.autoImportCompletions<\/td>\n<td>false<\/td>\n<td>false<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>python.analysis.showOnlyDirectDependenciesInAutoImport<\/td>\n<td>false<\/td>\n<td>false<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>python.analysis.packageIndexDepths<\/td>\n<td><code>[ { \"name\": \"sklearn\", \"depth\": 2 }, { \"name\": \"matplotlib\", \"depth\": 2 }, { \"name\": \"scipy\", \"depth\": 2 }, { \"name\": \"django\", \"depth\": 2 }, { \"name\": \"flask\", \"depth\": 2 }, { \"name\": \"fastapi\", \"depth\": 2 } ]<\/code> | <code>[ { \"name\": \"sklearn\", \"depth\": 2 }, { \"name\": \"matplotlib\", \"depth\": 2 }, { \"name\": \"scipy\", \"depth\": 2 }, { \"name\": \"django\", \"depth\": 2 }, { \"name\": \"flask\", \"depth\": 2 }, { \"name\": \"fastapi\", \"depth\": 2 } ]<\/code> | <code>{ \"name\": \"\", \"depth\": 4,  \"includeAllSymbols\": true }<\/code><\/td>\n<\/tr>\n<tr>\n<td>python.analysis.regenerateStdLibIndices<\/td>\n<td>false<\/td>\n<td>false<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>python.analysis.userFileIndexingLimit<\/td>\n<td>2000<\/td>\n<td>2000<\/td>\n<td>-1<\/td>\n<\/tr>\n<tr>\n<td>python.analysis.includeAliasesFromUserFiles<\/td>\n<td>false<\/td>\n<td>false<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>python.analysis.functionReturnTypes<\/td>\n<td>false<\/td>\n<td>false<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>python.analysis.pytestParameters<\/td>\n<td>false<\/td>\n<td>false<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>python.analysis.supportRestructuredText<\/td>\n<td>false<\/td>\n<td>false<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>python.analysis.supportDocstringTemplate<\/td>\n<td>false<\/td>\n<td>false<\/td>\n<td>true<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Other Changes and Enhancements<\/h2>\n<p>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:<\/p>\n<ul>\n<li><strong><a href=\"https:\/\/devblogs.microsoft.com\/python\/python-in-visual-studio-code-june-2023-release\/#test-discovery-and-execution-rewrite\">The testing rewrite<\/a> nearing default status<\/strong>: This release addresses <a href=\"https:\/\/github.com\/microsoft\/vscode-python\/issues\/23279\">the final known issue<\/a> in the testing rewrite, and we plan to turn off the rewrite experiment and set it to the default in early 2025<\/li>\n<li>Python Native REPL handles window reload in <a href=\"https:\/\/github.com\/microsoft\/vscode-python\/issues\/24021\">@vscode-python#24021<\/a><\/li>\n<li>Leave focus on editor after Smart Send to Native REPL in <a href=\"https:\/\/github.com\/microsoft\/vscode-python\/issues\/23843#issuecomment-2439025852\">@vscode-python#23843<\/a><\/li>\n<li>Add error communication around dynamic adapter activation in <a href=\"https:\/\/github.com\/microsoft\/vscode-python\/issues\/23234\">@vscode-python#23234<\/a><\/li>\n<li>Pytest <code>--rootdir<\/code> argument for pytest is now dynamically adjusted based on the presence of a <code>python.testing.cwd<\/code> setting in your workspace in <a href=\"https:\/\/github.com\/microsoft\/vscode-python\/issues\/9553\">@vscode-python#9553<\/a><\/li>\n<li>Add support for interpreter paths with spaces in the debugger extension in <a href=\"https:\/\/github.com\/microsoft\/vscode-python-debugger\/issues\/233\">@vscode-python-debugger#233<\/a><\/li>\n<li><code>pytest-describe<\/code> plugin is supported with test detection and execution in the UI in <a href=\"https:\/\/github.com\/microsoft\/vscode-python\/issues\/21705\">@vscode-python#21705<\/a><\/li>\n<li>Test coverage support updated to handle NoSource exceptions in <a href=\"https:\/\/github.com\/microsoft\/vscode-python\/issues\/24366\">@vscode-python#24366<\/a><\/li>\n<li>Restarting a test debugging session now reruns only the specified tests in <a href=\"https:\/\/github.com\/microsoft\/vscode-python-debugger\/issues\/338\">@vscode-python-debugger#338<\/a><\/li>\n<li>The testing rewrite now leverages FIFO instead of UDS for inter-process communication allowing users to harness pytest plugins like <code>pytest_socket<\/code> in their own testing design in <a href=\"https:\/\/github.com\/microsoft\/vscode-python\/issues\/23279\">@vscode-python#23279<\/a><\/li>\n<\/ul>\n<p>We would also like to extend special thanks to this month&#8217;s contributors:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/joar\">@joar<\/a> Ruff 0.8.0 fixes in <a href=\"https:\/\/github.com\/microsoft\/vscode-python\/pull\/24488\">@vscode-python#24488<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/renan-r-santos\">@renan-r-santos<\/a> Add native pixi locator in <a href=\"https:\/\/github.com\/microsoft\/vscode-python\/pull\/244420\">@vscode-python#244420<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/tomoki\">@tomoki<\/a> Fix the wrong Content-Length in <code>python-server.py<\/code> for non-ascii characters in <a href=\"https:\/\/github.com\/microsoft\/vscode-python\/pull\/24480\">@vscode-python#24480<\/a><\/li>\n<\/ul>\n<p>Try out these new improvements by downloading the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-python.python\">Python extension<\/a> and the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-toolsai.jupyter\">Jupyter extension<\/a> from the Marketplace, or install them directly from the extensions view in Visual Studio Code (Ctrl + Shift + X or \u2318 + \u21e7 + X). You can learn more about <a href=\"https:\/\/code.visualstudio.com\/docs\/python\/python-tutorial\">Python support in Visual Studio Code<\/a> in the documentation. If you run into any problems or have suggestions, <a href=\"https:\/\/github.com\/microsoft\/vscode-python\/issues\/new\/choose\">please file an issue<\/a> on the <a href=\"https:\/\/github.com\/Microsoft\/vscode-python\">Python VS Code GitHub page<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The December 2024 release of the Python and Jupyter extensions for Visual Studio Code are now available. This month&#8217;s updates include a special review of docstring generation features from Pylance, the new Python Environments extension in preview, Pylance&#8217;s &#8220;full&#8221; language server mode, and much more. Keep reading to learn more!<\/p>\n","protected":false},"author":173659,"featured_media":10119,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[662,17],"class_list":["post-9956","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-documentation","tag-python"],"acf":[],"blog_post_summary":"<p>The December 2024 release of the Python and Jupyter extensions for Visual Studio Code are now available. This month&#8217;s updates include a special review of docstring generation features from Pylance, the new Python Environments extension in preview, Pylance&#8217;s &#8220;full&#8221; language server mode, and much more. Keep reading to learn more!<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/posts\/9956","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/users\/173659"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/comments?post=9956"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/posts\/9956\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/media\/10119"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/media?parent=9956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/categories?post=9956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/python\/wp-json\/wp\/v2\/tags?post=9956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}