Python in Visual Studio 15.7 Preview
Note: this blog post was first released for 15.7 Preview 1, and has been updated to reflect the latest as of 15.7 Preview 3
We have released the third preview of our next update to Visual Studio 2017. If you already have the preview installed you will see a notification in Visual Studio within the next few days, or you can download the preview installer from visualstudio.com.
In this post, we’re going to look at some of the new features we have added for Python developers. As always, the preview is a way for us to get features into your hands early, so you can provide feedback and we can identify issues with a smaller audience. If you encounter any trouble, please use the Report a Problem tool to let us know.
The two major new features are a preview of the ptvsd 4.0 debugger, and IntelliSense for type hints.
IntelliSense for Type Hints
In this release we have added support for type hints in our IntelliSense. When you add type hints to parameters or variables they’ll be shown in hover tooltips.
For example, in the example below a Vector type is declared as a list of floats, and the scale() method is decorated with types to indicate the parameters and return types. Hovering over the scale() method when calling it shows the expected parameters and return type:
Using type hints you can also declare class attributes and their types, which is handy if those attributes are dynamically added later. Below we declare that the Employee class has a name and an id, and that information is then available in IntelliSense when using variables of type Employee:
Right now you will see type hint information being combined with the automatic analysis we have always performed, but we are not using them to provide warnings about mismatched types. Let us know in the comments on this post how you would like to see this information being used in Visual Studio.
Preview of ptvsd 4.0 debugger
In this release we are experimenting with a new version of our ptvsd debug engine based on PyDevD, with a basic set of debugging features and some early performance improvements over the previous version that we want to make available for you to try out. A preview of the latest ptvsd has also been released in the Python extension for Visual Studio Code.
As one example of a new benefit, Django apps run faster with the new debugger attached (compared to the previous version). With our sample stackoverflow-django app we observed up to a 3x speedup in loading pages.
You can try it out by taking the following steps:
- Check “Use experimental debugger” in Tools > Options > Python > Experimental
- Restart Visual Studio
- Click Start debugging!
Features supported include:
- Launching applications
- Basic breakpoints and stepping over/into/out
- Break on exception
- View/change call stack frames
- View local and global variables
- Conditional breakpoints
Some features that we are still working on include:
- Set Next Statement
- Local and Remote Attach
- Django template debugging
While we are working hard on this new debugger, we will be publishing updates frequently. If you find a problem, try updating your ptvsd install as we may have already released a fix.
Be sure to download the latest preview of Visual Studio and try out the above improvements. If you encounter any issues, please use the Report a Problem tool to let us know (this can be found under Help, Send Feedback) or continue to use our GitHub page. Follow our Python blog to make sure you hear about our updates first, and thank you for using Visual Studio!