[Python-ideas] Technical possibilities for a syntax [was: Reverse assignment operators ...]

Nikolaus Rath Nikolaus at rath.org
Wed Nov 16 13:26:12 EST 2016


On Nov 16 2016, Ryan Gonzalez <rymg19-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
> A = A + 1  ==>  A += 1
>
>
> Similar problem: semantics change. If someone decided to be weird and have
> __add__ and __iadd__ do two different things, this would completely break
> that. Granted, that's a stupid idea to begin with, but it's still poor
> justification for the code breakage.

Aeh, that's used e.g. in numpy and most certaintly not weird.

x = np.range(5)
y = x**2
y_int = interpolate(x, y, copy=False)

y = y+1

print(y_int(3))

If you replace 'y = y + 1' with 'y += 1', then instead of creating a new
array and assigning it to y, you modify the existing array in place,
which will change the result of y_int(3). That is a feature.


Best,
-Nikolaus

-- 
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«


More information about the Python-ideas mailing list