Python BytesMichael Kennedy and Calvin Hendryx-ParkerAll episodes
#499 So many questions??
Topics covered in this episode:
- PEP 824 brings ?? and ??= to Python for None handling
- Python 3.15 gets a surprise RC3, and Python 3.10 reaches end of life
- asyncio.shield
- Pyxel: the retro game engine for Python
- Extras
- Joke
About the show
Sponsored by us! Support our work through:
- Our courses at Talk Python
- Consulting from Six Feet Up
Connect with the hosts
- Michael: Mastodon / BlueSky / X / LinkedIn
- Calvin: Mastodon / BlueSky / X / LinkedIn
- Show: Mastodon / BlueSky / X
Join us on YouTube at pythonbytes.fm/live to be part of the audience. Usually Tuesday at 7am PT. Older video versions available there too.
Finally, if you want an artisanal, hand-crafted digest of every week of the show notes in email form? Add your name and email to our friends of the show list, we'll never share it.
Michael #1: PEP 824 brings ?? and ??= to Python for None handling
PEP 824, a new draft from Marc Mueller sponsored by Guido van Rossum, proposes None-coalescing operators for Python 3.16. The ?? operator returns its left-hand side unless that value is None, and ??= assigns a fallback only when the target is None. It revives the long-deferred PEP 505 from over a decade ago, trimmed to just these two operators, with None-aware access split off into PEP 823. The goal is replacing verbose is None checks with something closer to or, but keyed on None instead of truthiness.
- Every Python codebase has piles of if x is None fallback code, and this is the first serious move in ten years to give it real syntax.
- user.age ?? "unknown" is like or but only falls back on None, so 0, "", and [] pass through instead of getting clobbered
- user.name ??= "unknown" replaces the two-line check-then-assign pattern, with left-side subexpressions evaluated and cached exactly once
- Precedence sits between or and conditional expressions, matching JavaScript and C#, and ?? lands as a BoolOp in the AST next to and and or
- Unlike +=, ??= is a conditional assignment that skips the right side entirely, which is why it gets its own AST node rather than AugAssign
- Still draft status targeting 3.16, with a working reference implementation and an online demo to try, and it notably rejects a soft keyword like otherwise in favor of the familiar ??
- Discussion-worthy: the PEP answers the old objection that making None easier will proliferate its use, pointing out None is already everywhere and the status quo just produces uglier code
# OG way
user = db.get_user()
city = None
if user is not None:
if user.address is not None:
if user.address.city is not None:
city = u