News

VS Code Python Team Improves Interactive REPL

Microsoft's dev team for Python in Visual Studio Code updated its tooling to improve working with the language's interactive REPL functionality.

Standing for Read-Eval-Print Loop, a REPL provides an interactive environment in which a developer can run code constructs to see how they work.

The team, responsible for the Python and Jupyter extensions in the VS Code marketplace, today (Nov. 2) announced experimental REPL behavior that ensures only complete code constructs that will actually execute are sent to the REPL.

"The Python extension is working on improving the behavior of sending code to the Python REPL (Shift+Enter) when no code has been explicitly selected to run," the team explained. "Previously, when you placed your cursor on a line of Python code and pressed Shift+Enter, the Python extension would send the exact line contents to the REPL, even if it would fail, for example, due to being part of a multi-line command.

"With our new experimental Smart Send feature, the Python extension will send the smallest runnable block of code surrounding the line where your cursor is to the REPL for execution. This ensures that only complete and executable sections of code are sent to the REPL. The cursor will also be automatically placed to the next executable line, to provide a smooth experience when executing multiple chunks iteratively."

[Click on image for larger, animated GIF view.] REPL Smart Send in Animated Action (source: Microsoft).

Developers can flip a configuration switch to try out the experimental Smart Send, which is expected to become the default behavior.

Other highlights of the November 2023 update to Python in Visual Studio Code include:

  • Deprecated built-in linting and formatting features: The team deprecated the built-in linting and formatting features that are shipped within the Python extension, including all the linting and formatting commands as well as settings (python.linting.* and python.formatting.*).
  • Improvements to Python linting extensions: These tools have been improved in several ways. One example: "The Pylint, Mypy and Flake8 extensions now offer settings that allow you to specify glob patterns for files that you wish to exclude from linting. This can be useful if you are working with a large codebase with many sub-projects, and want to exclude certain folders from being linted."
  • Reconfiguration of test output: "We've made significant improvements to how you can view and interact with the Test Output in the Python extension when the pythonTestAdapter experiment is enabled, which we announced a few months ago. Previously, output from test discovery and execution was inconsistently scattered across the Python Test Log output channel and the Test Results panel, with some information being duplicated in both places. To consolidate the experience, we are now displaying output related to test execution in the Test Results panel, and test discovery in the Python output channel. To learn more see our related wiki."
  • Virtual environment deactivation help: This involves an experiment enabling terminal activation using environment variables, which the team said can enhance development workflow by automatically activating the selected environment in the terminal without explicit activation commands. The deactivate command didn't work, though, due to no working activation scripts being available when the experiment was enabled. Now, the team said: "The Python extension will now detect when you attempt to run the deactivate command and show a helper notification that will guide you on how to add scripts for your shell to enable the command to work again when the environment is activated through environment variables. It also offers a button to more conveniently open your shell profile file for you to add the necessary scripts."
  • Announcing Python in VS Code release videos: Now, as is done with several Microsoft dev tool releases, an accompanying video will be published for future Python in Visual Studio Code releases to highlight key changes and provide demos. The first one, from Python Community Advocate Dawn Wages, runs just over two minutes and is available here.

The team's Python and Jupyter extensions rank first and third in popularity in the marketplace, accounting for nearly 174 million combined downloads. More information about the team's offerings is available in Microsoft's "Getting Started with Python in VS Code" documentation.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

Subscribe on YouTube