News

What's New with Python in the Latest Visual Studio Preview

Just before Stack Overflow deemed Python the "fastest-growing major programming language," Microsoft conveniently detailed updates for using the language in the new Visual Studio 15.4 Preview 1.

Even before Stack Overflow's announcement, however, Python was a rising star in the development world, buoyed by its easy-to-learn simplicity, affinity for Big Data analytics and more.

In July, for example, it topped the IEEE Spectrum programming language ranking, at about the same time a Packt Publishing Ltd. survey named it the most popular development tool of any kind.

"Its popularity has surged over recent years and it has clearly gained huge mainstream uptake due to its accessibility, fully featured standard library, rich ecosystem of libraries and frameworks, and highly engaged community," Packt said at the time.

Regular readers of Visual Studio Magazine's Data Science Lab column by Dr. James McCaffrey (of Microsoft Research) know it's one of his favorite tools, and he gives a nice introduction to using it in an MSDN Magazine article.

With that popularity in mind, the Visual Studio team at Microsoft has been busy incorporating Python-related functionality into its flagship IDE. In April, Microsoft Python guru Steve Dower noted that "As of today, the Python development and Data Science and Analytical Applications workloads are stable and ready for production use".

Just a couple weeks ago, he updated Python's progress in Visual Studio 15.4 Preview 1, discussing new features and even "the secret tricks and exclusive downloads you will need to enable some of them."

For one thing, Dower noted, Python is one of the first programming languages to support a new way to use the "Go To Definition" feature of Visual Studio that lets coders navigate to the source of a type and open the result in a new tab.

"You are probably familiar with the Go To Definition feature, either through the editor context menu or the F12 shortcut key, but we have added a new way to use it," Dower said. "While holding the Control key down, the identifier you have the mouse over will turn into a hyperlink if it has definitions you can go to. Clicking on the item will then take you directly to the definition." The functionality can be customized, with developers able to choose a key other than the Control key, and "peek" at a definition rather than navigate to it (a feature not working in preview 1 but being fixed for preview 2).

Note that this feature is available as a Visual Studio Marketplace extension -- appropriately named "Ctrl+Click Go To Definition," that has been installed more than 151,000 times.

Speaking of extensions, Dower also announced the release of a separate extension that enables debugging in the Windows Subsystem for Linux (WSL).

Debugging in the Windows Subsystem for Linux
[Click on image for larger view.] Debugging in the Windows Subsystem for Linux (source: Microsoft).

"After installing this extension, you can select a new debug launcher in Python project properties," Dower said. "Now, when you press F5, your project will launch under WSL using the most compatible version of Python available (for example, a project using Python 3.6 will try to launch with python3.6 and then python3 before returning an error).

"Once running, the debugger will automatically attach, providing the great experience you are used to getting with local or remote debugging."

The Microsoft.PythonTools.Wsl.VS2017.vsix extension, which can be downloaded here, comes with this caveat:

Warnings: This is a highly experimental extension, and we're releasing it separately because we may change it dramatically when fully integrated into Visual Studio, or we may decide not to integrate it at all. You may need to manually uninstall the extension before installing future Visual Studio updates. While this extension is completely unsupported, we would love to hear your feedback on GitHub. This download will only be available for a limited time and is only compatible with Visual Studio 15.4 Preview 1.

Yet another extension -- carrying the same warning -- allows for native Python debugging from within C++ projects. Similar mixed C/Python debugging was previously supported, but only in Python projects. "Selecting this debugger for your C++ project will launch with support for viewing Python types and stack frames, giving you the best experience for debugging your application," Dower said.

That Microsoft.PythonTools.Debugger.VCLauncher.VS2017.vsix extension can be installed from here.

Finally, developers brave enough to risk fooling around with the registry editor can create a new key that improves IntelliSense results. Basically, it lets developers obviate the creation of a "completion database" to provide IntelliSense hints.

"Our IntelliSense is based on some really intense static analysis that infers types for every possible variable, and it takes time to get those results," Dower said. "But in many cases, very simple syntax analysis can provide results that will keep you productive, especially when combined with your own expertise.

"So we've been working on a brand new approach that does not rely on generating a completion DB. This means that when you install a new environment or a new package, we will give you great IntelliSense immediately, without having to run the background process at all."

It's so new and experimental that it's disabled by default, thus requiring tweaking the registry in order to use it. Dower doesn't recommend enabling it for production environments.

Dower asked developers to submit feedback on these improvements in the Python Tools for Visual Studio site for Issues on GitHub.

About the Author

David Ramel is the editor of Visual Studio Magazine.

comments powered by Disqus
Upcoming Events

.NET Insight

Sign up for our newsletter.

I agree to this site's Privacy Policy.