cache isinstance(default, collections.Callable)

This commit is contained in:
qubesuser 2017-11-09 18:17:58 +01:00
parent 9cc86b3be2
commit b297ecbcf1

View File

@ -200,6 +200,10 @@ class property(object): # pylint: disable=redefined-builtin,invalid-name
lambda self, prop, value: str(value)) lambda self, prop, value: str(value))
self.type = type self.type = type
self._default = default self._default = default
self._default_function = None
if isinstance(default, collections.Callable):
self._default_function = default
self._write_once = write_once self._write_once = write_once
self.order = order self.order = order
self.load_stage = load_stage self.load_stage = load_stage
@ -227,8 +231,8 @@ class property(object): # pylint: disable=redefined-builtin,invalid-name
if self._default is self._NO_DEFAULT: if self._default is self._NO_DEFAULT:
raise AttributeError( raise AttributeError(
'property {!r} have no default'.format(self.__name__)) 'property {!r} have no default'.format(self.__name__))
elif isinstance(self._default, collections.Callable): elif self._default_function:
return self._default(instance) return self._default_function(instance)
else: else:
return self._default return self._default