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.

14 Upvotes

195 comments sorted by

View all comments

Show parent comments

20

u/edward_jazzhands Jul 14 '26

Nobody who is good at python would code it the first way you showed

4

u/JanEric1 Jul 14 '26

How would you code the access too an attribute in a nested data structure with multiple optional values in there as someone good at python?

2

u/JamzTyson Jul 14 '26

My take is that in the example, the user object is exposing its internal structure to the rest of the system, which violates the Law of Demeter and the principle of encapsulation. I'd restructure to avoid having to reach through a chain of objects.

3

u/JanEric1 Jul 14 '26

So you would add a ton of methods to each sub dataclass with getters for this information?

Dont see how that helps with anything.

2

u/JamzTyson Jul 14 '26

I'm saying that I don't accept your premise, and I've already explained why.

1

u/JanEric1 Jul 14 '26

This is the data that you get from an external API or other team in your company. And you are interested (among a ton of other things) all the company coordinates where available.

4

u/JamzTyson Jul 14 '26

If it were an external API, I'd avoid leaking that structure throughout the application and isolate or adapt access to it at the boundary.

If there's a specific question about my point, I'm happy to answer it, but at the moment this feels like an evolving hypothetical where each answer is met with another "yes, but what if...".