Point-assignment operator

Point-assignment operator, e.g.:

.=
.0=
.1=

This operator will return certain result from the right expression.
Example code:

thread .= Thread(target=func).start()
# same:
# thread .0= Thread(target=func).start()
thread.join()
###
outer_dict .1= some_dict.setdefault('outer', dict()).setdefault('key', 1)
print(outer_dict)
# {'key': 1}

And with tuple of labels on the left:

obj, result .= SomeClass().calc_result()

What problem does this solve?

I think you first example

thread .= Thread(target=func).start()

is already writeable as

(thread := Thread(target=func)).start()

which seems a lot clearer to me. And I don’t even like the assignment expression operator.

2 Likes

There is no point showing us examples of these operators .0= and .1= if you don’t tell us what the examples do. I have no idea what this is supposed to do:

thread .0= Thread(target=func).start()

You say: “This operator will return certain result from the right expression.”

That is not very helpful. Which result is returned?

I think I can guess what .= is supposed to do:

obj .= name  # like obj = obj.name

and you can follow the name with some other things which make an expression, e.g. these are valid:

obj .= method(arg)    # like obj = obj.method(arg)
obj .= attr[key] + 1  # like obj = obj.attr[key] + 1

but these are not valid:

obj .= None or method(arg)
obj .= 1 + attr[key]

but I have no clue what the .0= and .1= forms are supposed to represent, or whether they are limited to just 0 and 1, or can you use any arbitrary integer .93746=?

It seems to me that the existing set of augmented assignments += etc are not very useful, and have some quirks that trip up beginners. Sure, I use them as a shortcut, but maybe I shouldn’t :slight_smile: and I never missed them before Python had them.

It seems to me that this proposed .= augmented assignment is even less useful, but perhaps you can explain it better and make a good case for it.

1 Like

And the second example is writeable as
(outer_dict := some_dict.setdefault('outer', dict())).setdefault('key', 1)
I may be missing something, but I don’t think the original idea is useful for anything other than saving a line or 2 of code.