Skip to content

Instantly share code, notes, and snippets.

@koi8-r
Created February 27, 2020 13:54
Show Gist options
  • Save koi8-r/4105316400b9948ca4501ea6d86c170d to your computer and use it in GitHub Desktop.
Save koi8-r/4105316400b9948ca4501ea6d86c170d to your computer and use it in GitHub Desktop.
class Product(object):
url: str
def __getattribute__(self, name):
ret = object.__getattribute__(self, name)
if isinstance(ret, property):
return ret.__get__(self)
return ret
val = None
class LazyVal(object):
def get(self):
return getattr(self, '__val')
def set(self, val):
setattr(self, '__val', val)
def lazy_getter(self):
return val
def Lazy():
return property(lazy_getter)
product = Product()
product.url = Lazy() # Lazy(val)
print(product.url)
val = 9
print(product.url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment