This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author josh.r
Recipients josh.r, skypickle, steven.daprano
Date 2019-05-21.01:16:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1558401379.57.0.950724014939.issue36980@roundup.psfhosted.org>
In-reply-to
Content
1. This is a bug tracker for bugs in the Python language spec and the CPython interpreter, not a general problem solving site.

2. The ids will differ for changeValue2 if you actually call it (kernel = kernel + 2 requires the the old id of kernel differ from the new id, because they both exist simultaneously, and are different objects); I'm guessing you're calling the wrong function or printing the ids of the wrong variables.

3. "Would it possible for the python interpreter/compiler to let me know when a function is going to clobber a variable that is not used in the function or passed to the function or returned by the function" Every bit of clobbering you're seeing involves a variable passed to the function (and sometimes returned by it). CVkernel=myKernel just made two names that bind to the same underlying object, so passing either name as an argument to a function that modifies its arguments will modify what is seen from both names. That's how mutable objects work. This is briefly addressed in the tutorial here: https://docs.python.org/3/tutorial/classes.html#a-word-about-names-and-objects . As a general rule, Python built-ins *either* modify their arguments in place and return nothing (None) *or* return new values leaving the arguments unmodified. It's a matter of programmer discipline to adhere to this practice in your own code (numpy does make it harder, since it uses views extensively, making slicing not an effective way to copy inputs).

All that said, this isn't a bug. It's a longstanding feature of Python alias arguments to avoid expensive deep copies by default; the onus is on the function writer to copy if needed, or to document the behavior if mutation of the arguments is to occur.
History
Date User Action Args
2019-05-21 01:16:19josh.rsetrecipients: + josh.r, steven.daprano, skypickle
2019-05-21 01:16:19josh.rsetmessageid: <1558401379.57.0.950724014939.issue36980@roundup.psfhosted.org>
2019-05-21 01:16:19josh.rlinkissue36980 messages
2019-05-21 01:16:19josh.rcreate