
On Thu, 12 Mar 2020 at 19:10, Andrew Barnert <abarnert@yahoo.com.via.e4ward.com> wrote:
No, because the return value only lives until (effectively) the end of the statement. A statement has no value, so the effect of an expression statement is to immediately discard whatever the value of the expression was. (In CPython this is an explicit stack pop.)
Except for the case of interactive mode, of course, where an expression statement binds the value to the _ variable.
Okay, so it seems I was confused by the REPL feature. Anyway, since the object is not discarded until the expression statement ends, it has no effect on speed. On the contrary, for what I have read, the numpy patch removes the temporary ndarrays immediately. This speeds up calcula with large ndarrays. So there's no need to change the `del` behaviour. Python could implement something similar to the numpy patch for large immutables. The problem is: how?