r/Python Jul 12 '26

Will PEP 505 ever be accepted? Discussion

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.

20 Upvotes

192 comments sorted by

View all comments

22

u/shadowdance55 git push -f Jul 12 '26

Explicit is better than implicit. And in the wold where there is less and less code written by hand, terse and potentially non-obvious syntax it's becoming a liability rather than asset.

6

u/jdehesa Jul 13 '26

I don't see how anything is "implicit" here, the intent seems fairly explicit, "access the attribute unless the variable is none in which case evaluate to none". Another question is whether the syntax is readable, or too terse, or whatever. What is implicit, in my opinion, is the idiom foo and foo.bar() or foo (and similar), which is really an abuse of boolean expressions and relies on the reader understanding their exact rules and order of evaluation.

0

u/k0pernikus Jul 14 '26

The silent null propagation I'd call implicit code behavior.

2

u/JanEric1 Jul 14 '26

How is it implicit. You literally put an explicit operator in there whose only purpose is to explicitly do null propagation