[issue46612] Unclear behavior of += operator

2022-02-02 Thread Eric V. Smith
Change by Eric V. Smith : -- resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python tracker ___ ___ Python-

[issue46612] Unclear behavior of += operator

2022-02-02 Thread Marek Scholle
Marek Scholle added the comment: > a += b means (is closest to) a = type(a).__iadd__(a, b) I exchanged several messages, and this is all I needed! I propose to resolve as "Not a bug" -- ___ Python tracker _

[issue46612] Unclear behavior of += operator

2022-02-02 Thread Vedran Čačić
Vedran Čačić added the comment: You've managed to write 3 messages already, without at any point mentioning what _really_ happens when you += something. a += b means (is closest to) a = type(a).__iadd__(a, b) You focus all the time on __iadd__ call, disregarding that its result it assign

[issue46612] Unclear behavior of += operator

2022-02-02 Thread Marek Scholle
Marek Scholle added the comment: I don't understand the comment https://bugs.python.org/issue46612#msg412374 >>> def f(): x ... >>> f() is OK, so x is something which can be evaluated inside nested function, it is a good target to be used in `x.__iadd__(iterable)`. That >>> d

[issue46612] Unclear behavior of += operator

2022-02-02 Thread Eric V. Smith
Eric V. Smith added the comment: The "evaluate the target" part causes the UnboundLocalError, just as in: >>> x=1 >>> def f(): ... x ... x = x + 1 ... >>> f() Traceback (most recent call last): File "", line 1, in File "", line 2, in f UnboundLocalError: local variable 'x' referenced

[issue46612] Unclear behavior of += operator

2022-02-02 Thread Marek Scholle
Marek Scholle added the comment: Thanks for pointing to reference https://docs.python.org/3/reference/simple_stmts.html#augmented-assignment-statements Although I can agree it tries to point to similarity with `x = x + 1`, it says about how `x += [1]` is processed: (1) evaluate the target (

[issue46612] Unclear behavior of += operator

2022-02-02 Thread Steven D'Aprano
Steven D'Aprano added the comment: You say: "The documentation says ..." but don't tell us which documentation. This documentation: https://docs.python.org/3/reference/simple_stmts.html#augmented-assignment-statements tells us that augmented assignment is assignment: "An augmented assignme

[issue46612] Unclear behavior of += operator

2022-02-02 Thread Marek Scholle
New submission from Marek Scholle : Hi, I ran into discussion about scoping in Python (visibility of outer variables in nested functions, global, nonlocal) which made me to create for other some showcases. I realized there is a space for ambiguity which I extracted to this REPL: >>> x =