models: Make sure sub-classes can extend models

This commit is contained in:
Thomas Adamcik 2015-04-29 21:32:43 +02:00
parent 8851fb151c
commit 94039e06dc
2 changed files with 10 additions and 1 deletions

View File

@ -22,7 +22,8 @@ class ImmutableObjectMeta(type):
attrs['_fields'] = fields
attrs['_instances'] = weakref.WeakValueDictionary()
attrs['__slots__'] = ['_hash'] + fields.values()
attrs['__slots__'] = list(attrs.get('__slots__', []))
attrs['__slots__'].extend(['_hash'] + fields.values())
for ancestor in [b for base in bases for b in inspect.getmro(base)]:
if '__weakref__' in getattr(ancestor, '__slots__', []):

View File

@ -18,6 +18,14 @@ class InheritanceTest(unittest.TestCase):
class Foo(Track):
pass
def test_sub_class_can_have_its_own_slots(self):
class Foo(Track):
__slots__ = ('_foo',)
f = Foo()
f._foo = 123
class CachingTest(unittest.TestCase):