Читаю статью по декораторам, и наткнулся на одним не совсем понятный момент… Подскажите, пожалуйста.
Статья.
8 часть, имеется код:
>>> def outer(): ... x = 1 ... def inner(): ... print x # 1 ... return inner >>> foo = outer() >>> foo.func_closure # doctest: +ELLIPSIS (<cell at 0x...: int object at 0x...>,)
Далее - идёт объяснение, почему он не должен бы сработать (но - да, он работает):
> We aren’t able to call inner till after the return of outer so according to our model of how Python works, x shouldn’t exist anymore by the time we call inner and perhaps a runtime error of some kind should occur.
Но - почему `We aren't`, если мы сохранили outer() в foo, со всем её пространством имён и переменными?