On Sun, May 26, 2019 at 10:25 PM Chris Angelico
On Mon, May 27, 2019 at 6:05 AM Yanghao Hua
wrote: Doesn't matter how it ends up, I urge the python community do give it a second thought. (Don't you guys think it is odd that Python can overrides almost every operation but not for assignment ... is assignment really worthy being a special case?!)
Yes. It IS a special case, because assignment is not handled by the object being assigned to. When you assign to an attribute or subscript of an object, the *parent* object determines how the assignment is done, not the one being replaced. Look at languages where the being-replaced object gets to redefine assignment (C++ and PHP come to mind, and there may be others). MANY MANY parts of your code become harder to comprehend. It's not the only thing special enough to be non-overridable. In Python, you have several fundamentals that are absolutely guaranteed:
a = b a is b b if a else c a or b # a and b
There is no way that the values of a, b, or c can change the meanings of these expressions. (The truthiness of 'a' will define which of two options is chosen, but you cannot redefine the operator itself.)
This is a Good Thing.
Absolutely right and good. But if you just had := or <== mean "assignment behavior is handover to the object if __assign__ is defined", then you can remove the whole descriptors thing (or rather, it can do all a descriptor can and better, and actually := or <== is saying, hey look, I am a descriptor ... ) . ;-) I am not saying "=" should be overloaded, I am saying there should be an assignment that can be overloaded, which completes the picture in python.