From 5d15a496b1daf1312526b8b0a7d3cc4eb14f465c Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 17 Dec 2009 20:21:39 +0100 Subject: [PATCH] [fix] mixed inheritance between osv and osv_memory, add direct osv_base holding redundancies between osv and osv_memory and forcing resolution of its __init__ before going higher the class tree bzr revid: xmo@tinyerp.com-20091217192139-z9pnlw7d0438u89q --- bin/osv/orm.py | 2 +- bin/osv/osv.py | 35 +++++++---------------------------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 0d8e36031f7..a326b6b23e3 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1531,7 +1531,7 @@ class orm_memory(orm_template): _check_time = 20 def __init__(self, cr): - orm_template.__init__(self, cr) + super(orm_memory, self).__init__(cr) self.datas = {} self.next_id = 0 self.check_id = 0 diff --git a/bin/osv/osv.py b/bin/osv/osv.py index 6f795fe3ee9..5b2e4ee8da8 100644 --- a/bin/osv/osv.py +++ b/bin/osv/osv.py @@ -171,9 +171,12 @@ class osv_pool(netsvc.Service): res.append(klass.createInstance(self, module, cr)) return res +class osv_base(object): + def __init__(self, pool, cr): + pool.add(self._name, self) + self.pool = pool + super(osv_base, self).__init__(cr) -class osv_memory(orm.orm_memory): - #__metaclass__ = inheritor def __new__(cls): module = str(cls)[6:] module = module[:len(module)-1] @@ -186,6 +189,7 @@ class osv_memory(orm.orm_memory): module_list.append(cls._module) return None +class osv_memory(osv_base, orm.orm_memory): # # Goal: try to apply inheritancy at the instanciation level and # put objects in the pool var @@ -213,27 +217,7 @@ class osv_memory(orm.orm_memory): return obj createInstance = classmethod(createInstance) - def __init__(self, pool, cr): - pool.add(self._name, self) - self.pool = pool - orm.orm_memory.__init__(self, cr) - - - -class osv(orm.orm): - #__metaclass__ = inheritor - def __new__(cls): - module = str(cls)[6:] - module = module[:len(module)-1] - module = module.split('.')[0][2:] - if not hasattr(cls, '_module'): - cls._module = module - module_class_list.setdefault(cls._module, []).append(cls) - class_pool[cls._name] = cls - if module not in module_list: - module_list.append(cls._module) - return None - +class osv(osv_base, orm.orm): # # Goal: try to apply inheritancy at the instanciation level and # put objects in the pool var @@ -270,10 +254,5 @@ class osv(orm.orm): return obj createInstance = classmethod(createInstance) - def __init__(self, pool, cr): - pool.add(self._name, self) - self.pool = pool - orm.orm.__init__(self, cr) - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: