Conversation
|
@gvanrossum And please can you confirm sponsorship of this as well as #4798? |
Yes of course. |
gvanrossum
left a comment
There was a problem hiding this comment.
Again, I love that these get a serious treatment and I hope we can get the PEP to make it into 3.15. Again I have some editorial suggestions (some of which are generic and could apply to 823 as well) and some grammar nits and typos.
Hnasar
left a comment
There was a problem hiding this comment.
Thanks for writing this up in such a clear way. Exciting to see this move forward!
|
I do think that "coalescing" is a rather off-putting term, and we should come up with a better name for all proposed operations (?., ??, ??=). |
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Documentation build overview
57 files changed ·
|
|
Again, sorry for the long delay here. Took some time to rewrite most of the motivation section. I dropped the whole argument that Also extended the "How to Teach This" section to point out
Other changes
|
|
Hey @cdce8p! I noticed two small things in the current PEP 824 draft that I would like to inquire about: First, the assignment expression alternative in the "Motivation" section looks like it has its evaluation order backwards: age = (val := user.get_age()) if val is not None else "unknown"Because the condition of a conditional expression is evaluated first, this reads In [15]: age = (val := user.get_age()) if val is not None else "unknown"
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[15], line 1
----> 1 age = (val := user.get_age()) if val is not None else "unknown"
NameError: name 'val' is not defined
In [16]: age = val if (val := user.get_age()) is not None else "unknown"
In [17]: age
Out[17]: 20I think the intended version is: age = val if (val := user.get_age()) is not None else "unknown"Second, do you think we could have the specification explicitly describe how get_container()[get_key()] ??= make_default()To me what should happen is _container = get_container()
_key = get_key()
_current = _container[_key]
if _current is None:
_container[_key] = make_default()The reference implementation seems to agree with this, but I think documenting it would be useful, since the current Thanks for your time and looking forward to this PEP helping my code less verbose ;) |
|
Thanks for taking the time to read the draft and provide feedback @gtkacz! If you like a challenge, I've another open PR for the none-aware access operators, feel free to read #4798.
Yes. This must have slipped through at some point.
Your intuition is correct here. Subexpressions on the left hand side are cached. This is actually similar to augmented assignments. My reference implementation for |
|
@cdce8p more than happy to help! Your other PEP 823 will also be an incredible QOL improvement, and I'd love to help with it, but I'm not sure what would you'd want me to do? I'll move the convo there ;) |
gvanrossum
left a comment
There was a problem hiding this comment.
Lots of nits, a few biggies (I don't like the "coalesce" name). Great PEP!
| peps/pep-0820.rst @encukou | ||
| peps/pep-0821.rst @JelleZijlstra | ||
| peps/pep-0822.rst @methane | ||
| # ... |
There was a problem hiding this comment.
Why the # ... ? If it's to fend off a merge conflict with the PR for PEP 823, I think there's a better way to do that (just fix the second PR after the first one has landed).
There was a problem hiding this comment.
This was added in 68d6ded. I believe # ... is used in the CODEOWNERS file to show a missing PEP number. It's used a few times throughout the file.
Tbh I don't think it really matters. Resolving the inevitable merge conflict will get rid of it.
| Discussions-To: Pending | ||
| Status: Draft | ||
| Type: Standards Track | ||
| Created: 24-Jun-2026 |
There was a problem hiding this comment.
Maybe change this to the day the PR lands?
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
gvanrossum
left a comment
There was a problem hiding this comment.
Another round. While at a C++ conference I finally found the time to look at these. :-)
| The general idea is to provide a comparison operator, similar to ``or``, | ||
| which instead of truthiness, checks for ``None`` values. | ||
|
|
||
| Explicit checks for ``None`` |
There was a problem hiding this comment.
"You shouldn't be using None as default in the first place. Use an empty tuple instead."
The tuple doesn't work so well if the value is annotated as : list[int], for example.
You can circumvent the argument by using another mutable container type, e.g. dict or set.
And was that really the argument that got 505? That'd be quite silly.
PEP 671 is deader than 505, because Chris Angelico had an episode on the thread.
My secret idea is that after this PEP is accepted, we can propose using ??= to indicate deferred argument defaults. If you squint a little it's the perfect operator for that situation. It would mean that an explicitly passed None also coalesces to the default, but that's behavior I like. And if you don't want that you can do it using the hard way using a custom sentinel value; but my way covers most common use cases.
Basic requirements (all PEP Types)
pep-NNNN.rst), PR title (PEP 123: <Title of PEP>) andPEPheaderAuthororSponsor, and formally confirmed their approvalAuthor,Status(Draft),TypeandCreatedheaders filled out correctlyPEP-Delegate,Topic,RequiresandReplacesheaders completed if appropriate.github/CODEOWNERSfor the PEPStandards Track requirements
Python-Versionset to valid (pre-beta) future Python version, if relevantDiscussions-ToandPost-History📚 Documentation preview 📚: https://pep-previews--4799.org.readthedocs.build/