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.

Title: Proposed FAQ entry on pass-by-? semantics and the meaning of 'variable' in python
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.2, Python 3.3, Python 2.7
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: docs@python Nosy List: brian.curtin, docs@python, eric.araujo, ezio.melotti, georg.brandl, michael.foord, r.david.murray, rprosser, terry.reedy
Priority: normal Keywords:

Created on 2010-02-06 21:04 by r.david.murray, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
pass_by_x.faq r.david.murray, 2010-02-06 21:04
passbyx.txt r.david.murray, 2010-02-06 22:03
Messages (10)
msg98956 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-02-06 21:04
A while back, after along discussion about variables and their meaning in Python on the python-list, I wrote up the attached FAQ entry to summarize what I got out of that enlightening discussion.  I'm proposing that this be added to the FAQs.  If this doesn't itself cause too much controversy I'll prepare a doc patch.
msg98957 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-02-06 21:16
Wasn't the description of Python's semantics being 'pass by value where the value is a reference' actually very controversial indeed? Do you have a link to the discussion on c.l.p?
msg98958 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-02-06 21:26
Well, the discussion was *long* and more than a bit contentious.  This is my own personal summary.  Here is a message I found somewhere in the middle of the thread:

Do you have a pointer to where "pass by value where the value is a reference" was controversial?  (Other than that thread :)
msg98959 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-02-06 21:34
The 4-point list at the beginning is in my opinion very clear (for people with some background in C or similar languages). I think that the following part is not really clear, and the example should focus better on the difference about mutable and immutable objects.
msg98960 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-02-06 21:37
Well, the thrust of the second part is to make it clear that there *are* no differences between mutable and immutable objects as far as the assignment semantics are concerned.  All objects in Python are treated the same.  What is different is what is on the left hand side of the assignment, and yes, it would probably be helpful to point that out explicitly.
msg98961 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-02-06 21:45
Over 122 messages so I'm not going to search exhaustively. In this part of the thread you can see Fredrik Lundh and Aahz disputing "call-by-value-where-the-value-is-a-reference" as a useful way of describing Python calling semantices:
msg98962 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-02-06 21:47
The difference is that mutable objects may give the illusion of a pass-by-reference (because changes made inside the function are visible outside) whereas immutable objects give the illusion of pass-by-value (because you can't affect the original object in any way). This is also related to the confusion about assignment and what it really does.
msg98963 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-02-06 22:03
Michael: I didn't read the whole thread, but it has definite echos of the thread in which I was involved.  While I agree that in pure computer-science terms it may be imprecise to say that python is 'call by value where values are pointers to objects", my goal in the FAQ entry is to give people coming from C a mental model that *works* in practical terms to help them understand what Python does.

The second half is then an attempt to provide a new mental model, one independent of any implementation details, that *better* explains what Python does.

But apparently, given Ezio's responses, I didn't succeed in the second part :(

Ezio: I've added another paragraph to the end to try to make the point I'm trying to get across clearer, but I'm not sure the additional words really do that.
msg109943 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-07-10 23:23
I and others completely disagree with "Technically the correct answer is 'pass by value',". This confuses the C implementation with the abstract semantics of Python. The correct answer is neither. Nothing is 'passed'.

A better form of the question would be "Does Python use call-by-value or call-by-reference?" The answer would still be 'neither'. Python is different from Fortran, C, and the other languages to which those terms apply. And because both are wrong, both lead to wrong expectations.

Python binds argument objects to parameter names in the function's local namespace. This is 'call by object', the term used by Barbara Liskov, chief developer of the object-based CLU language that did the same long before Python. I would call *that* the 'technically correct answer.

Yes, this has been very controversial on python-list.
msg130480 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-03-10 00:59
This patch isn't going to be accepted, so I'm closing the issue.  Someone else can propose a different wording in a new issue if they wish.
Date User Action Args
2022-04-11 14:56:57adminsetgithub: 52115
2011-12-12 10:09:45ezio.melottisetnosy: + rprosser

versions: - Python 3.1
2011-03-10 00:59:50r.david.murraysetstatus: open -> closed
nosy: georg.brandl, terry.reedy, ezio.melotti, eric.araujo, r.david.murray, michael.foord, brian.curtin, docs@python
messages: + msg130480

resolution: rejected
stage: resolved
2011-03-09 04:12:23terry.reedysetnosy: georg.brandl, terry.reedy, ezio.melotti, eric.araujo, r.david.murray, michael.foord, brian.curtin, docs@python
versions: + Python 3.3
2011-03-01 11:08:12eric.araujosetnosy: + eric.araujo
2010-08-07 18:37:38terry.reedysetversions: - Python 2.6
2010-07-10 23:24:01terry.reedysetassignee: georg.brandl -> docs@python

nosy: + docs@python
2010-07-10 23:23:42terry.reedysetnosy: + terry.reedy
messages: + msg109943
2010-02-06 22:15:55brian.curtinsetnosy: + brian.curtin
2010-02-06 22:03:02r.david.murraysetfiles: + passbyx.txt

messages: + msg98963
2010-02-06 21:47:10ezio.melottisetmessages: + msg98962
2010-02-06 21:45:06michael.foordsetmessages: + msg98961
2010-02-06 21:37:39r.david.murraysetmessages: + msg98960
2010-02-06 21:34:03ezio.melottisetnosy: + ezio.melotti
messages: + msg98959
2010-02-06 21:26:15r.david.murraysetmessages: + msg98958
2010-02-06 21:16:39michael.foordsetnosy: + michael.foord
messages: + msg98957
2010-02-06 21:04:13r.david.murraycreate