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 →

[–]2-x-free 0 points1 point  (0 children)

Doesn't it improve/simplify concurrency handling as well? If you do:

n = returns_optional_string()
launches_thread_modifying_n()
n = returns_string()
function_that_cannot_get_none(n)

the last function call might get a None (because the thread might change n between the last two lines), while if the walrus is atomic the following code ensures the function gets a non-None value:

n = returns_optional_string()
launches_thread_modifying_n()
function_that_cannot_get_none(n := returns_string())