Python 3.15's quieter wins: TaskGroup.cancel, thread-safe iterators, ContextDecorator fixes
Beyond the headline features like lazy imports, Python 3.15 ships several smaller quality-of-life improvements worth knowing. asyncio.TaskGroup gains a cancel() method that replaces the awkward exception-raising-and-suppressing pattern previously needed to interrupt a group gracefully. ContextDecorator has been taught to recognize async functions, generators, and async generators when used as a decorator, fixing a long-standing footgun where the decorator would exit immediately instead of wrapping the full lifecycle of the wrapped callable.
The threading module picks up serialize_iterator, synchronized_iterator, and concurrent_tee, giving free-threaded and multi-threaded code a clean way to share or fan out iterator consumption without falling back to queues. Smaller additions round out the release: Counter gains an xor operator for symmetric-difference semantics on multisets, and the new frozendict combined with an array_hook parameter on json.load/loads makes it straightforward to parse JSON straight into fully immutable, hashable structures.
Taken together, these changes nudge Python toward cleaner concurrency primitives and more ergonomic functional patterns, even if none of them will dominate the release notes.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.