Message242619
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. |
|
Date |
User |
Action |
Args |
2015-05-05 20:51:59 | levkivskyi | set | recipients:
+ levkivskyi, docs@python |
2015-05-05 20:51:59 | levkivskyi | set | messageid: <1430859119.42.0.185221847455.issue24129@psf.upfronthosting.co.za> |
2015-05-05 20:51:59 | levkivskyi | link | issue24129 messages |
2015-05-05 20:51:58 | levkivskyi | create | |
|