Hi Konatan, welcome! Comments below.
On Wed, Sep 30, 2020 at 06:41:04PM +0300, Jonatan wrote:
it would be nice if you could implement also __igetattr__ or something, which means:
instead of con = "some text here" con = con.replace("here", "there")
we could do
con = "some text here" con .= replace("here", "there")
An interesting idea. You should have a read of the original PEP for augmented assignment and see how well this idea fits the original proposal:
You can ignore anything about `__coerce__`, that method is gone from Python now.
I think this might make good sense for string methods:
mystring = mystring.upper() mystring .= upper()
but less so for arbitrary objects with methods returning arbitrary values, or methods that operate in place.
There's also the factor that the dot operator is not very visually distinctive. "Syntax shouldn't look like grit on Uncle Tim's monitor", although of course we already have the dot for attribute access, so this isn't a really strong argument.
But more importantly, unless the right hand side is severely limited, it is going to be very hard to be unambiguous. The standard augmented assignments take *any expression at all* for the right hand side:
value += 2*x - y
but this could not:
value .= 2*x - y
I'm not entirely sure what would be allowed.
mystring .= (strip() or default).upper()
Would you expect that to work?