librelist archives

« back to archive

question on internals: LocalProxy()

question on internals: LocalProxy()

From:
paalzza
Date:
2013-03-06 @ 23:55
hello all!

im trying to get acquainted with flask/werkzeug internals.

in function:

class LocalStack():

     def __call__(self):
         def _lookup():
             rv = self.top
             if rv is None:
                 raise RuntimeError('object unbound')
             return rv
         return LocalProxy(_lookup)

a LocalProxy is used.
Why do we need to use it here?
Why cant we do it just simple without _lookup and LocalProxy-ing it? 
like so:

class LocalStack():

     def __call__(self):
         rv = self.top
         if rv is None:
             raise RuntimeError('object unbound')
         return rv

thanks