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.
17
Upvotes
View all comments
Show parent comment
1
u/k0pernikus Jul 15 '26 edited Jul 15 '26
You don't need to silence them. You need to parse them. You parse API content once, and then you'll have no null / None anywhere to pop up. You either filter them out or transform them.
At most it gets replaced into empty lists (that are better at saying: empty as they are still loopable, it's just that the loop becomes a noop), or exceptions if you depend on the API output (you must still classify the exception as an API or a parsing bug -- or maybe API querying bug; yet that you'll can do directly after the error report), or proper NullObjects or since 3.15 sentinel values (so you can distinguish between API had the literal null in there, or the API had it undefined; I also treat certain API output as API-unique sentinels, as I had API return a string "undefined" on me for properties.)
The idea is to deal with the None values at the boundary of your core so your code, by design, need not to make any None checks, as it's impossible for None to even be passed down.
And even when are none passes through per accident, my strict boundary will fail. I then fix my parser. Any T|None and any if value is None check inside my core are code smell that I'm not parsing correctly.