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 levkivskyi
Recipients docs@python, levkivskyi
Date 2015-05-05.20:51:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1430859119.42.0.185221847455.issue24129@psf.upfronthosting.co.za>
In-reply-to
Content
The documentation on execution model https://docs.python.org/3/reference/executionmodel.html contains the statement
"""
A class definition is an executable statement that may use and define names. These references follow the normal rules for name resolution. The namespace of the class definition becomes the attribute dictionary of the class. Names defined at the class scope are not visible in methods.
"""
However, the following code (taken from http://lackingrhoticity.blogspot.ch/2008/08/4-python-variable-binding-oddities.html):

x = "xtop"
y = "ytop"
def func():
    x = "xlocal"
    y = "ylocal"
    class C:
        print(x)
        print(y)
        y = 1
func()

prints

xlocal
ytop

In case of "normal rules for name resolution" it should rise UnboundLocalError.

I suggest replacing the mentioned statement with the following:
"""
A class definition is an executable statement that may use and define names. Free variables follow the normal rules for name resolution, bound variables are looked up in the global namespace. The namespace of the class definition becomes the attribute dictionary of the class. Names defined at the class scope are not visible in methods.
"""
or a similar one.
History
Date User Action Args
2015-05-05 20:51:59levkivskyisetrecipients: + levkivskyi, docs@python
2015-05-05 20:51:59levkivskyisetmessageid: <1430859119.42.0.185221847455.issue24129@psf.upfronthosting.co.za>
2015-05-05 20:51:59levkivskyilinkissue24129 messages
2015-05-05 20:51:58levkivskyicreate