Python 3.11 -
Before 3.11, if you ran multiple tasks and two failed with different errors, Python would raise the first exception and swallow the second. You would lose debugging information.
async def main(): tasks = [risky_task("A", True), risky_task("B", False), risky_task("C", True)] try: results = await gather( tasks, return_exceptions=False) except ValueError as eg: for exc in eg.exceptions: print(f"Handling: exc") Handling: A failed Handling: C failed
import tomllib with open("config.toml", "rb") as f: config = tomllib.load(f) print(config["tool"]["poetry"]["name"]) python 3.11
# Python 3.10 Traceback (most recent call last): File "calc.py", line 2, in <module> result = 100 / (50 - 50) ZeroDivisionError: division by zero Traceback (most recent call last): File "calc.py", line 2, in <module> result = 100 / (50 - 50) ~~~~^~~~~~~~~~~~ ZeroDivisionError: division by zero
If you are still on Python 3.8 or 3.9, here is why you should make the jump to 3.11 (or later). The headline feature of Python 3.11 is the result of Microsoft’s "Faster CPython" team, led by Mark Shannon. For years, Python developers accepted the trade-off of slower execution for rapid development speed. Python 3.11 narrowed that gap significantly. Before 3
Notice the except* (star-except) syntax. It catches all ValueErrors inside the group without breaking the successful execution of task "B". Ask any developer: "What is the worst part of Python?" Many will answer: Tracebacks that only tell you the line, not the column.
If you are starting a new project today, target . Your future self will thank you for the speed and clarity. Want to test it yourself? Install via pyenv or the official Python Docker image python:3.11-slim . The headline feature of Python 3
Python 3.11 adds tomllib to the standard library for reading TOML files.