Commits

Carl Friedrich Bolz committed 4a5fa74

be able to get at the class of an instance

Comments (0)

Files changed (2)

         assert len(obj.storage) == attr.length()
 
 
+class Terminator(AbstractAttribute):
+    def __init__(self, cls=None):
+        self.cls = cls
 
-class Terminator(AbstractAttribute):
     def read(self, obj, attrname):
         return None
 
     def get_terminator(self):
         return self
 
+
 class PlainAttribute(AbstractAttribute):
     def __init__(self, attrname, back):
         self.attrname = attrname
     def get_terminator(self):
         return self.back.get_terminator()
 
+# ____________________________________________________________
+
+
 class Object(object):
     def __init__(self, map, storage):
         self.map = map
         new_obj = self.map.delete(self, attrname)
         self.map = new_obj.map
         self.storage = new_obj.storage
+
+    def get_class(self):
+        return self.map.get_terminator().cls
+
+class Class(object):
+    def __init__(self):
+        self.terminator = Terminator(self)
+
+    def instantiate(self):
+        return Object(self.terminator, [])
         s = [50, 60, 70]
         del s[i]
         assert obj.storage == s
+
+def test_class():
+    c = Class()
+    obj = c.instantiate()
+    assert obj.get_class() is c
+    obj.write("a", 50)
+    assert obj.get_class() is c
+    obj.write("b", 60)
+    assert obj.get_class() is c
+    obj.write("c", 70)
+    assert obj.get_class() is c