Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def __get__(self, instance, owner):
"""
Instead of directly returning the value directory, we look up each instance's value using
the instance itself as the key.
"""
if instance is not None: # attribute lookup initiated from instance
if len(self._instance_values) < NonNullStringDescriptor.CAPACITY:
self._instance_values[instance] = self.__default
return self._instance_values.get(instance, self.__default)
else: # attribute lookup initiated via class
return self.__default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment