Merge pull request #2824 from strikaco/attrprop

AttributeProperty tries spawning child instances of default value (#2697)
This commit is contained in:
Griatch 2022-08-14 16:45:46 +02:00 committed by GitHub
commit 261156da69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -202,6 +202,21 @@ class AttributeProperty:
self._lockstring = lockstring
self._autocreate = autocreate
self._key = ""
@property
def _default(self):
"""
Tries returning a new instance of default if callable.
"""
if callable(self.__default):
return self.__default()
return self.__default
@_default.setter
def _default(self, value):
self.__default = value
def __set_name__(self, cls, name):
"""