What’s New in PyCharm 2021.2

PyCharm 2021.2: New Python 3.10 Features, HTML Preview: Browser Page Reload on Save, Collaborative Mode in the Python Console

Code insight

Python 3.10

Find out how you can benefit from Python 3.10’s new functionality with PyCharm – even before Python 3.10’s stable release! We started working on support for Python 3.10 by delivering code insight for Explicit Type Aliases (PEP 613) in PyCharm 2020.3. In this release, we have introduced support for even more PEPs.

Pattern Matching (PEPs 634, 635, 636)

Pattern Matching (PEPs 634, 635, 636)

Structural Pattern Matching is coming in Python 3.10. PyCharm provides a number of key features to help you adjust to its arrival, like the Unused local symbols and Unreachable code inspections, smart code completion and syntax highlighting for the match and case keywords, and the Complete Current Statement action.

Complete Current Statement
Complete Current Statement

PyCharm can now complete match statements and their corresponding case blocks. Once you’re done typing an initial match statement, you can choose Complete Current Statement (Shift+Ctrl+Enter) and PyCharm will complete the remaining part, including the colon and the first part of the case block. The caret will be left in place for you to start typing the rest of the case block.

Formatter
Formatter

PyCharm’s built-in formatter recognizes match statements and helps you format them correctly.

New syntax for union types (PEP 604)

New syntax for union types (PEP 604)

In Python 3.10 you will be able to use int | str for union types instead of Union[int, str]. This functionality is already available in earlier versions of Python through the use of from __future__ import annotations.

PyCharm provides overall code insight for the new syntax, including intention actions and information in the Quick Documentation. PyCharm now supports type inference for isinstance and issubclass arguments with the new syntax type.

Further improvements:

  • The type checker recognizes typing.Literal in various collection types, which makes it possible to match against specific values of the collections’ elements. This works even for nested collections.
  • You can use the doctest injection in Markdown to demonstrate the execution of Python code in REPL mode as though it were being executed in the Python console.

Collaborative development: Code With Me

Python console support

Python console support

Working in the Python console is now supported on both the client machine and the host side. During a collaborative coding session, guests can review the code while the host runs it in the interactive console. Support for the Python console in Code With Me comes complete with all the usual PyCharm features, such as on-the-fly syntax highlighting with inspections and code completion.

Synchronized code completion

Synchronized code completion

When you are in Following mode during a Code With Me session, it is possible to keep track of which code completion suggestions the person you are following uses. Also, for any session type, guests’ completion results are exactly the same as they would have been for the host.

Further improvements:

Code With Me recently launched two new relay servers: one on the west coast of the US and another one in South Africa. This has made the ping almost three times faster.

IDE improvements

Tool window for Python packages: install packages from custom locations

Tool window for Python packages: install packages from custom locations

In PyCharm 2021.1 we implemented the Python Packages tool window to manage packages for the currently selected Python interpreter. Now you can install packages, not only from the PyPI repository, but also from VCS or a local machine. Click the Add Package link on the Python Packages toolbar and select From Version Control | From Disc.

Accessibility updates

PyCharm 2021.2 includes a number of helpful updates for coding with screen reader mode enabled on macOS. It will narrate code completion suggestions, the content of the selected combo box and combo box lists, and the results of your queries in Search Everywhere.

Further improvements:

  • We’ve added a number of actions that will be initiated by saving the project, including reformatting code and optimizing imports. All of them are gathered in Preferences/Settings | Tools | Actions on Save.
  • It is now easier to drag and drop a tool window to the desired place within the main IDE window or in a separate window. You can drag it by clicking and holding the tool window name bar, and you can drop it in any highlighted area.
  • Upload custom icons by right-clicking on a project on the Welcome screen and selecting Choose project icon from the context menu.
  • Starting with this version, you can enjoy a fully localized UI in Chinese, Korean, or Japanese. Localization is available as a non-bundled language pack plugin, which can be easily installed in your IDE.

Databases Pro only

Code completion for fields and operators in the MongoDB console

Code completion for fields and operators in the MongoDB console

Now PyCharm can complete fields, nested fields, and fields inside aggregation expressions, as well as query operators, projection operators, update operators, and aggregation stages in the MongoDB console.

Context live templates from the data editor with SQL scripts action

Context live templates from the data editor with SQL scripts action

Context live templates now work directly from the data editor. If you’re working with a table and you wish to query it, you can easily do so with the help of the SQL scripts action!

Frontend development Pro only

Reload pages in browser on save

Reload pages in browser on save

PyCharm lets you preview HTML files in a browser using the built-in web server. Now it is able to automatically update the pages in a browser as you edit and save your HTML, CSS, and JavaScript files. To get started, open an HTML file in the editor, hover over the corner of the editor, and click on the icon for the browser you want to use – all browsers are supported.

Rename refactoring for React useState hooks

Rename refactoring for React useState hooks

You will no longer need to waste time on refactoring useState values and functions one by one – PyCharm can now rename both for you! Place the caret on a state value and press Shift+F6 or go to Refactor | Rename from the right-click context menu.

Auto-import for require()

Auto-import for require()

Did you know that PyCharm can add missing import statements as you complete ES6 symbols? Now it can do the same for CommonJS modules – require imports will be inserted on code completion.

Further improvements:

Adding new project dependencies to package.json has become even easier, as code completion now works for private npm packages. PyCharm lets you check information about the latest versions of the package, just like it does for public packages.

Version Control

Changes to pre-commit checks

Changes to pre-commit checks

We’ve expanded the list of possible pre-commit actions with the ability to execute tests. Tick the Run Tests checkbox in the Before Commit section to test the applied changes. You can also customize the Analyze code and Cleanup options by clicking Choose profile next to them. The progress and results of all the pre-commit checks appear in the Commit area.

Space plugin

Connect PyCharm to your organization in JetBrains Space to view and clone project repositories and to review your teammates’ code. To log in to Space, click the Get from VCS button on the Welcome screen, select Space on the left, and enter your organization URL in the dedicated field.

Space job statuses in the Git log

Space job statuses in the Git log

It is easy to track a job’s progress by just looking at the commits list, as we’ve introduced icons for Space job statuses in the Log tab of the Git tool window. If you click on an icon, the IDE will open a popup with the automation info for that job.

If you don’t need the status information, click the eye icon above the log and select Show Columns | Space Automation.

Branch display in code reviews

Branch display in code reviews

Your IDE can now show related branches in the selected code review. You can see the list of branches that contain the commits made while working on the current issue in the Details tab.

Mention teammates

Mention teammates

Communicating with teammates in Space code reviews is now more convenient, as you can mention them with @ followed by the colleague’s name. This minor but helpful feature works in the timeline and in code comments.

Further improvements:

  • Secure your commits by enabling Git commit signing with GPG. To do this, go to Preferences/Settings | Version Control | Git, click Configure GPG Key, and then select it from the drop-down list.

Please note that features marked Pro only are supported only in PyCharm Professional Edition.