From 0c577dd6608d544341b091446be92dc0b2dee8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 23 Dec 2012 22:58:13 +0100 Subject: [PATCH] Improve getattr lookup in fields.Function.get review612003 --- trytond/model/fields/function.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/trytond/model/fields/function.py b/trytond/model/fields/function.py index ee78513408..1971cad0bb 100644 --- a/trytond/model/fields/function.py +++ b/trytond/model/fields/function.py @@ -74,8 +74,9 @@ class Function(Field): If the function has ``names`` in the function definition then it will call it with a list of name. ''' + method = getattr(Model, self.getter) + def call(name): - method = getattr(Model, self.getter) records = Model.browse(ids) if not hasattr(method, 'im_self') or method.im_self: return method(records, name) @@ -84,12 +85,12 @@ class Function(Field): if isinstance(name, list): names = name # Test is the function works with a list of names - if 'names' in inspect.getargspec(getattr(Model, self.getter))[0]: + if 'names' in inspect.getargspec(method)[0]: return call(names) return dict((name, call(name)) for name in names) else: # Test is the function works with a list of names - if 'names' in inspect.getargspec(getattr(Model, self.getter))[0]: + if 'names' in inspect.getargspec(method)[0]: name = [name] return call(name)