Следующее работает хорошо, т.е. не выдает никаких ошибок:
def foo(arg):
class Nested(object):
x = arg
foo('hello')
Но следующее бросает исключение:
def foo(arg):
class Nested(object):
arg = arg # note that names are the same
foo('hello')
Traceback:
Traceback (most recent call last):
File "test.py", line 6, in <module>
foo('hello')
File "test.py", line 3, in foo
class Nested(object):
File "test.py", line 4, in Nested
arg = arg
NameError: name 'arg' is not defined
Я не могу понять причину такого поведения. Кто-нибудь может объяснить?