openerp-expert-framework team mailing list archive
-
openerp-expert-framework team
-
Mailing list archive
-
Message #00542
Re: Updated OpenERP API in trunk: fields.function, osv loading
On 2011-07-04, at 17:19 , Leonardo Santagada wrote:
> 2011/7/4 Olivier Dony <odo@xxxxxxxxxxx>:
>> 1) fields.function() does not take a "method" parameter anymore [1]. It
>> was useless and every field was passing method=True. It is possible to
>> pass a normal function too, it simply needs to have the proper signature
>> (see the docstring). Don't forget to run 'bzr pull' on the server,
>> otherwise the trunk addons will not work anymore.
>> And please do not use the "method" parameter anymore in trunk! (it's
>> ignored, though, so it's backwards compatible)
>
> I saw the changeset[1], but why not introspect the function to know if
> it is a method or a function?
Because technically, the callable passed is never a method (unless you're
doing pretty strange stuff with it): it has not yet been collected and
converted by the class statement (that only happens after the class body
has finished executing), so it's always a function taking an arbitrary
object as its first argument (the object happens to be the current class
instance, so it looks like it's a method form within it):
>>> store = None
>>> def set_store(callable):
... global store
... store = callable
...
>>> class Foo(object):
... def some_method(self):
... print 4
... set_store(some_method)
...
>>> Foo.some_method
<unbound method Foo.some_method>
>>> Foo().some_method
<bound method Foo.some_method of <__main__.Foo object at 0x1004cd910>>
>>> store
<function some_method at 0x1004b92a8>
The value of `store` is what is really stored in function fields: a function,
which takes one argument, which happens to be called `self`.
References