Skip to content

Instantly share code, notes, and snippets.

@dhermes
Created November 4, 2014 22:07
Show Gist options
  • Select an option

  • Save dhermes/2f833d9d3706a52b559d to your computer and use it in GitHub Desktop.

Select an option

Save dhermes/2f833d9d3706a52b559d to your computer and use it in GitHub Desktop.
def _require_loaded(method):
"""Wrapper for an instance method to allow lazy loading."""
@functools.wraps(method)
def wrapped_method(self, *args, **kwargs):
"""Wrapped version of an instance method which requires loaded.
If the instance value of loaded is not True, then this will
reload before calling the method.
"""
if not self.loaded:
self.reload()
return method(self, *args, **kwargs)
return wrapped_method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment