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.
18
Upvotes
View all comments
Show parent comment
1
u/Anthony356 Jul 14 '26
Or, as is common for glue code in a scripting language, you do not have full control over your inputs. The moment you need to read untrusted data, or versioned data where new fields are added to the schema, you have to check for
Noneeverywhere.Sure, i could parse the data into a structure i do control, but that's just rearranging the furniture (and doesnt always solve the
Nonechecking problem anyway). You still have to check somewhere, and that boilerplate distracts from the actual intent of the code, the actual operation you're doing on the data if it exists.This is not some mystical pattern that takes 700iq to understand. It's simple, it happens everywhere, all the time. For such cases, languages have operators.
I dont understand how any argument against
?couldnt also apply to like...+, orand/orshort circuiting, or list comprehensions, orwithstatements, or a million other things.