r/Python • u/philtrondaboss • Jul 12 '26
Discussion Will PEP 505 ever be accepted?
https://peps.python.org/pep-0505/
I don't understand how null safe operators are less like plain English than other implemented features like the walrus operator.
In my opinion, the member access operator would make python significantly easier to read and understand.
Here's an example:
f = foo()
if f is None:
baz = ""
else:
baz = f.bar()
baz = foo()?.bar() ?: ""
EDIT: I forgot that "and" and "or" can be sometimes used in place of "?." and "?:" if the left value is not False, '', 0, [], or {}. It's a very implicit null check and has a lot of unexpected behavior.
16
Upvotes
View all comments
Show parent comment
0
u/k0pernikus Jul 14 '26
You are talking different aspects. The ? adds mental load to parse what could have been an easily readable branch. Yes, the null coalescing operator is an explicit language construct; also yes it makes the code more error prone and harder to reason about esp if you need to figure out where the none originated from during a bug hunt.
And no, I don't mean that that if-else are inherently better, and you can create the same problematic pattern with them as well, yet the sheer boilerplate alone should make you think: maybe I'm doing it wrong. By using abundant null coalescing operators you are hiding the code smell in plain sight.
Where you see a helpful explicit and conciselanguage construct, others see a loophole for anti patterns to manifest.