classification
Title: default value of argument seems to be overwritten
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: approximately, serhiy.storchaka, steven.daprano
Priority: normal Keywords:

Created on 2017-04-22 04:19 by approximately, last changed 2017-04-22 17:44 by steven.daprano. This issue is now closed.

Files
File name Uploaded Description Edit
misc_math.7z approximately, 2017-04-22 04:19 Two Python scripts, only one character changed
Messages (5)
msg292100 - (view) Author: Klaus Wolf (approximately) Date: 2017-04-22 04:19
Two function results differ if the parameter is given explictly instead of using the given default.

(Enclosed example: A small simple interpreter of Forth language, both scripts should give the same result, but the first one (variant1) fails because the value from the first pass remains on the stack.)
msg292110 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-22 06:31
See "Why are default values shared between objects?" in Python FAQ (https://docs.python.org/3/faq/programming.html#id13).
msg292113 - (view) Author: Klaus Wolf (approximately) Date: 2017-04-22 11:51
A documented misbheavior is still a misbehavior.
msg292118 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-22 12:31
This is correct behavior. You just made a common mistake made by newcomers. Read Python FAQ and other resources, this can help you to avoid other pitfalls.
msg292129 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2017-04-22 17:44
In the future please don't post binary files containing source code, especially something as non-standard as 7z. That just makes it difficult for people to review the code. Either paste your code snippet directly into the bug report, or attach it as a .py file.

If the file is so huge it needs compression, you shouldn't be posting it at all. You should post the *minimum* code to demonstrate the problem, not an entire application: we don't a 200 line simulation of a Forth interpreter just to see something that can be shown in ten lines. Even though this is written for Java programmers, the same applies here: http://sscce.org/


Thank you.
History
Date User Action Args
2017-04-22 17:44:42steven.dapranosetnosy: + steven.daprano
messages: + msg292129
2017-04-22 12:31:56serhiy.storchakasetmessages: + msg292118
2017-04-22 11:51:45approximatelysetmessages: + msg292113
2017-04-22 06:31:18serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg292110

resolution: not a bug
stage: resolved
2017-04-22 04:19:14approximatelycreate