A culmination of great work done by volunteers worldwide, the release of Python 3.10 dominated the Python community’s news cycle in October 2021. At the same time that this release was making new features available, Python got recognition as the top programming language for the month in the TIOBE Programming Community index.
There are also some new opportunities for you to support the community by participating in the Python Developer Survey and answering the PyCon US 2022 Call for Proposals.
Let’s dive into the biggest Python news from the past month!
Free Bonus: Click here to get a Python Cheat Sheet and learn the basics of Python 3, like working with data types, dictionaries, lists, and Python functions.
The Python 3.10 Release
New versions of Python are now released annually. We can look forward to the core developers sharing a lovely goody bag with the rest of us every October. With Python 3.10, which came out of beta on October 4th, everyone had something exciting to anticipate.
Each release of Python has a release manager who’s responsible for coordinating all changes and for building and preparing the files for distribution. The release manager for Python 3.10 and 3.11 is Pablo Galindo Salgado. In a first for Python, he built and released Python live on YouTube.
Python 3.10 Highlights
The new release includes lots of improvements to the language. Among our favorites are improved error messages, simplified syntax for type unions, and structural pattern matching.
Improved error messages will make your life easier, whether you’re a new Python developer or an experienced one. In particular, the feedback that you get when your code isn’t valid Python is more pointed and actionable in Python 3.10 than in previous versions. As an example, consider the following code, where there’s no closing bracket at the end of the first line:
news = ["errors", "types", "patterns" print(", ".join(news))
In Python 3.9 and earlier, you’ll see the following if you try to run this code:
File "errors.py", line 2 print(", ".join(news)) ^ SyntaxError: invalid syntax
invalid syntax explanation isn’t very insightful. To make matters worse, the reported line number is wrong. The actual error happens on line 1—not on line 2, as the error message says. The new parser, which was introduced in Python 3.9, allows for much better feedback:
File "errors.py", line 1 news = ["errors", "types", "patterns" ^ SyntaxError: '[' was never closed
The line number is correct, and the accompanying explanation is to the point. This will allow you to jump right in, fix the error, and carry on coding!
Simplified syntax for type unions allows you to use type hints, often without any extra imports. You can use type hints to annotate your code, get increased support from your editor, and catch bugs earlier.
typing module is a centerpiece for adding static types to Python. However, over the last few releases, more and more tools have moved from
typing to built-in functionality. In Python 3.10, you’re allowed to use the pipe operator (
|) to specify type unions instead of importing
typing. The following code snippet shows an example of the new syntax:
def mean(numbers: list[float | int]) -> float | None: return sum(numbers) / len(numbers) if numbers else None
The annotation of
number specifies that it’s supposed to be a list of
int objects. Previously, you might have written this as
List[Union[float, int]]. Similarly, the annotation of the return value,
float | None, is a special case of a type union that you can also write as
Optional[float]. The new syntax means that you can annotate a lot of your code without even importing
Structural pattern matching is a powerful way of working with data structures that you may know from functional languages like Elixir, Scala, and Haskell. We previewed this feature in our newsletters in March and August.
Structural pattern matching is at its best when you need to manipulate lists, dictionaries, data classes, or other structures. The following example implements a recursive function that sums a list of numbers. It gives you a quick look at the new syntax:
def sum(numbers, accumulator=0): match numbers: case : return accumulator case [head, *tail]: return sum(tail, accumulator + head)
This code uses
accumulator to keep track of the running total. You match
numbers to two different cases.
In the first case,
numbers is an empty list. Since you don’t need to add more to your sum, you can return
accumulator. The second case accounts for what to do when there’s at least one element in the list: you name the first element
head, and you name the rest of the list
tail. You add
head to your running total and then recursively call
sum() for the remaining elements.
You can implement the same algorithm using
if statements. However, the new syntax opens up a more functional way of thinking about Python code, which can be an interesting avenue to explore going forward.
Dig into the details of these improvements, along with all the other new features in Python 3.10, in our dedicated tutorial.
A Live Python 3.10 Release Party on YouTube
Usually, the actual release of a new Python version happens behind closed doors. Although it’s announced well in advance, the link to download the new version tends to appear rather suddenly.
This year was different! Release manager Pablo Galindo Salgado and Leon Sandøy from Python Discord invited everyone to a release party live on YouTube. Despite the Internet having a bad day, the live stream worked out great and we could all watch as Pablo ran his magical scripts that make Python available for the whole world.
In addition to Pablo and Leon, several other core contributors joined the party:
- Łukasz Langa presented the updates to the typing system.
- Brandt Bucher introduced structural pattern matching.
- Carol Willing led a discussion about the Python community.
- Irit Katriel showed how to contribute to CPython development.
The stream is still available. Check it out if you’re interested in getting a unique look under the hood and seeing what it takes to release a new version of Python.
Python’s #1 Spot at TIOBE
The TIOBE Programming Community index is an indicator of the popularity of programming languages. It’s based on results from search engines and has been tracked for over 20 years.
In the October rankings, Python reached the number one spot for the first time. In fact, this was the first time a language not named Java or C has topped the index.
While this is just one index, the result confirms that Python is a very popular programming language that still has a lot of interest around it, with lots of great resources for developers available online.
Python Developers Survey 2021
The annual Python Developers Survey is open. This survey is very important for understanding how the community uses the Python language and the ecosystem supporting it. Results from earlier years have given lots of insights. These results are important inputs for many parts of the community to plan out how to use their limited resources.
If you’re available to contribute your answers, you can do so by opening the survey. The questions are quite diverse, but you can plan to get through them in about ten to fifteen minutes. This year, there are a few new questions that will help the developer in residence and the packaging project manager in their work.
PyCon US 2022: Call for Proposals
Preparations for PyCon US 2022 are well underway. The conference will take place in Salt Lake City from April 27th to May 5th of next year. As usual, the conference will consist of two days of tutorial workshops, three days of talks and other presentations, and four days of sprints where you can work together with other Python coders in the community.
If you want to present at PyCon, have a look at the call for proposals. The deadline for submitting your proposal is December 20th, 2021. There are four kinds of presentations that you can contribute:
- Talks are usually thirty minutes long and are held during the main conference days, from April 29th to May 1st.
- Charlas are talks given in Spanish. There will be one track of charlas on Friday, April 29th.
- Tutorials are three-hour workshops done on the first two days of the conference, April 27th and April 28th.
- Posters are presented in the conference hall during the main conference days, from April 29th to May 1st.
PyCon encourages anyone to submit a proposal, independent of your experience level. Go to PyCon’s submission page to learn more.
Visual Studio Code in Your Browser
The Visual Studio Code editor is a favorite of many Python developers. As part of the October release, the editor became available in a zero-install version that runs entirely in your browser.
You can open VS Code for the web by navigating to vscode.dev. Once you’re there, you can open files—and even directories, on supported browsers—and start working. There are some features that aren’t supported, including the terminal and the debugger. Still, you’ll have a good editing experience with most of the features and extensions you’re used to from the desktop version.
The web editor gives you instant access to code stored in GitHub or Azure. You can navigate to a repository and then add
vscode.dev in front of the URL to open it inside of the editor. For example, you can open the repository at
github.com/realpython/reader by entering
vscode.dev/github.com/realpython/reader as your URL. This is similar to—but not exactly the same as—pressing . to start an editor when you’re looking at a repository in GitHub.
What’s Next for Python?
October will always be an exciting month for Python with its releases for new versions of the language. At Real Python, we’re looking forward to digging further into Python 3.10, and we can’t wait to see what new things are in store for us in November.
What’s your favorite piece of Python news from October? Did we miss anything notable? Let us know in the comments, and we might feature you in next month’s Python news roundup.