Eryk Sun <[email protected]> added the comment:
If the target object of an augmented assignment doesn't support the in-place
binary operation, the normal binary operation is used instead. Thus an
augmented assignment is implemented to always assign the result back to the
target. For an attribute, that's similar to `x.a += 1` -> `x.a = x.a + 1`. For
example:
>>> dis.dis('x.a += 1')
0 RESUME 0
1 2 LOAD_NAME 0 (x)
4 DUP_TOP
6 LOAD_ATTR 1 (a)
8 LOAD_CONST 0 (1)
10 BINARY_OP 13 (+=)
12 ROT_TWO
14 STORE_ATTR 1 (a)
16 LOAD_CONST 1 (None)
18 RETURN_VALUE
Note the STORE_ATTR instruction in the above bytecode.
As to __slots__, I think that class construction should store it as a tuple,
unless maybe I'm overlooking some use case.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46550>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com