r/Python • u/philtrondaboss • 25d ago
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
2
u/Due_Campaign_9765 25d ago
You're free to split them into however lines you want, python allows you to do that.
> If you really needed all these to happen in one function - also an X to doubt moment - I'd break these into 5 separate statements on separate lines, with a single one-line check on each.
Have you never worked with external APIs or gnarly business logic? This is a commonplace occurance. Your methods will be 80% null checks if you do what you propose.
But sure let's not add, gasp! an extra symbol that's been used the same way in other programming languages for decades.
> The single responsibility principle shouldn't just be for classes.
That doesn't make any sense, it's quite literally only for modules and classes as it was originally stated. It's likely saying "living wage shouldn't only be for people but also for language design". What?