Fixed storedescs to work properly on derived types.
authorFredrik Tolf <fredrik@dolda2000.com>
Fri, 24 Jul 2015 13:25:01 +0000 (15:25 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Fri, 24 Jul 2015 13:25:01 +0000 (15:25 +0200)
didex/store.py

index 43c1348..55dc71e 100644 (file)
@@ -1,4 +1,4 @@
-import threading, pickle
+import threading, pickle, inspect
 from . import db, index, cache
 from .db import txnfun
 
@@ -35,13 +35,14 @@ class storedesc(object):
 
 def storedescs(obj):
     t = type(obj)
-    ret = getattr(t, "__didex_attr", None)
+    ret = t.__dict__.get("__didex_attr")
     if ret is None:
         ret = []
-        for nm, val in t.__dict__.items():
-            if isinstance(val, storedesc):
-                ret.append((nm, val))
-        t.__didex_attr = ret
+        for st in inspect.getmro(t):
+            for nm, val in st.__dict__.items():
+                if isinstance(val, storedesc):
+                    ret.append((nm, val))
+        t.__dict__["__didex_attr"] = ret
     return ret
 
 class datastore(object):