classification
Title: Redundant sentence in FAQ
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: demian.brecht, docs@python, ezio.melotti, fossilet, python-dev, r.david.murray, rbcollins, rhettinger
Priority: normal Keywords: patch

Created on 2015-03-05 08:32 by fossilet, last changed 2015-07-29 18:21 by rbcollins. This issue is now closed.

Files
File name Uploaded Description Edit
faq_fix.diff fossilet, 2015-03-05 08:32 review
faq_fix_1.diff fossilet, 2015-03-05 10:39 review
Messages (9)
msg237248 - (view) Author: Yongzhi Pan (fossilet) * Date: 2015-03-05 08:32
In https://docs.python.org/3/faq/programming.html#what-are-the-rules-for-local-and-global-variables-in-python, two sentences of essentially the same meaning exist. I try to remove this redundancy.
msg237255 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-03-05 10:18
How about:

In Python, variables that are only referenced inside a function are implicitly
global.  If a variable is assigned a value anywhere within the function's
body, it's assumed to be a local unless explicitly declared as global.
msg237256 - (view) Author: Yongzhi Pan (fossilet) * Date: 2015-03-05 10:39
Updated diff as Raymond's wording.
msg237261 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2015-03-05 11:48
I think the first sentence could be improved, even though it's correct.
A superficial reading might give the impression that function variables are implicitly global, or that only the variables inside a function are global, especially if the reader is not familiar with the term "referenced".
Swapping the two sentences and talking first about assignment might be enough to make clear that the other sentence is talking about variables that are only read/accessed by the function but not defined/assigned.
The paragraph can also be rephrased to say that Python can freely access variables from outer scopes, but that "global" is required to assign a new value to a global variable, and that variables defined inside a function are local.
msg237340 - (view) Author: Yongzhi Pan (fossilet) * Date: 2015-03-06 10:27
What about changing the first sentence to:

In Python, variables that are only referenced but not assigned inside a function are implicitly global.?
msg237341 - (view) Author: Yongzhi Pan (fossilet) * Date: 2015-03-06 10:46
Or:

In Python, variables inside a function that are only referenced but not assigned are implicitly global.?
msg237365 - (view) Author: Demian Brecht (demian.brecht) * (Python triager) Date: 2015-03-06 16:00
Not to throw a wrench into this, but would it perhaps not be worthwhile to refactor this section in order to include nonlocals as well (obviously not for 2.7)? It seems a little odd to me to have this amount of detail without mentioning nonlocal.
msg247591 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2015-07-29 18:13
@Demian, I agree that there are more improvements we can make. The current patch addresses the specific issue of this bug, and if you wished to make a new issue with further improvements that would be great. I'm going to apply this patch now though.
msg247592 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-07-29 18:20
New changeset 02f3bf3f74aa by Robert Collins in branch '2.7':
Issue #23589: Remove duplicate sentence from the FAQ.  Patch by Yongzhi Pan.
https://hg.python.org/cpython/rev/02f3bf3f74aa

New changeset 941b9c27b8c8 by Robert Collins in branch '3.4':
Issue #23589: Remove duplicate sentence from the FAQ.  Patch by Yongzhi Pan.
https://hg.python.org/cpython/rev/941b9c27b8c8

New changeset 93f3ca8fdc39 by Robert Collins in branch '3.5':
Issue #23589: Remove duplicate sentence from the FAQ.  Patch by Yongzhi Pan.
https://hg.python.org/cpython/rev/93f3ca8fdc39

New changeset 7163dd7e9511 by Robert Collins in branch 'default':
Issue #23589: Remove duplicate sentence from the FAQ.  Patch by Yongzhi Pan.
https://hg.python.org/cpython/rev/7163dd7e9511
History
Date User Action Args
2015-07-29 18:21:12rbcollinssetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2015-07-29 18:20:39python-devsetnosy: + python-dev
messages: + msg247592
2015-07-29 18:13:01rbcollinssetnosy: + rbcollins
messages: + msg247591
2015-03-06 16:00:33demian.brechtsetnosy: + demian.brecht
messages: + msg237365
2015-03-06 10:46:43fossiletsetmessages: + msg237341
2015-03-06 10:27:10fossiletsetmessages: + msg237340
2015-03-05 11:48:53ezio.melottisetnosy: + r.david.murray
messages: + msg237261
2015-03-05 10:40:00fossiletsetfiles: + faq_fix_1.diff

messages: + msg237256
2015-03-05 10:18:13rhettingersetnosy: + rhettinger
messages: + msg237255
2015-03-05 09:24:12ezio.melottisetassignee: docs@python -> ezio.melotti
stage: commit review

nosy: + ezio.melotti
versions: + Python 2.7, - Python 3.2, Python 3.3
2015-03-05 08:32:38fossiletcreate