r/Python • • 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

192 comments sorted by

View all comments

Show parent comment

1

u/Anthony356 Jul 14 '26

Counterpoint, which is more readable:

x = a & b
x = a.__and__(b)

Familiarity is only a problem once. Then you learn what it means (like with the & symbol) and from then on you read it the exact same as __and__ (or, more accurately, your brain automatically makes the association), it just takes up less space.

3

u/Technical_Income4722 Jul 14 '26 edited Jul 14 '26

I see where you're going, but & is already read as "and" in our minds when we see it so the substitution is free because it's already a synonym in our everyday language. A closer analog would be how & is used in C. It's a fundamental operator there and still trips people up all the time. Yeah obviously people could just be better and know their stuff, but I take you back to the ternary in C, which is clearly well-defined and convenient and yet still discouraged because it's just too easy to mix up.

Edit to add: I'm not even against the addition of this operator for folks who wanna use it, I mostly just disagree that it's more readable. I love using weird Python features (for-else my beloved) in my own code when I'm doing side projects.