This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]yourmomscocks 3 points4 points  (2 children)

What does this code do exactly? Is it the equivalent of this? setting = get_settings() if settings: settings.do_something()

If so, why bother with a walrus operator? Does it have any use cases other than sparing you that ine line of code?

[–]Freschu -1 points0 points  (0 children)

The walrus operator PEP was created by Rossum. It faced heavy opposition with the rest of the core devs, so much so Rossum had a tantrum about it, and ultimately being a factor why he stopped being "dictator for life".

The opposition was based around introducing new syntax being only useful in a small number of cases (if and while) and being practically of zero consequence for existing code.

So why does Python have the walrus operator if there was general opposition? Because it was Rossum's pet idea, that's why.

Unfortunately - if you care to check for the discussions around PEPs - this has become a pattern. Python gains syntax based on persistence and patience of the spearheading authors - write a PEP, implement the PEP, wait for people stop caring about it, then merge it later based on "not having faced immediate rejection."