models: Make sure sub-classes can extend models
This commit is contained in:
parent
8851fb151c
commit
94039e06dc
@ -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__', []):
|
||||
|
||||
@ -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):
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user