Avoid potential TypeErrors using LazyInitialise

This commit is contained in:
Kristóf Tóth 2018-06-02 11:25:48 +02:00
parent a743b01bcf
commit d5b0bb4d32

View File

@ -13,7 +13,7 @@ class LazyInitialise:
def __get__(self, instance, owner): def __get__(self, instance, owner):
if instance is None: if instance is None:
raise TypeError('Cannot get object property from class!') return self # avoids potential __new__ TypeError
value = self.func(instance) value = self.func(instance)
setattr(instance, self.func.__name__, value) setattr(instance, self.func.__name__, value)
return value return value