On 5/23/08, Stefan Behnel <[EMAIL PROTECTED]> wrote:
>  For the code below I get an exception at module load time:
>
>   File "classmethod.pyx", line 15, in classmethod (classmethod.c:507)
>  TypeError: Class-level classmethod() can only be called on a 
> method_descriptor
>  or instance method.
>
>  Is this what you meant?
>  http://codespeak.net/mailman/listinfo/cython-dev
>

No, the problem is really contrived. I wrote a simple test and tryed
to run it within the doctest infrastructure of Cython, but then the
problem does not show-up. Why? Because the method cache is surelly
being invalidated because of some Python code in the doctest
infrastructure, and then all works as expected. We have to try it
manually to see the issue in action. A small example below:

The Cython source code is this:

# file: classmeth.pyx
cdef class A:
    def foo(self):
        print(u"A.foo")
    def bar(cls):
        print(u"A.bar")
    bar = classmethod(bar)

After cythonizing and compiling:

$ python2.6
Python 2.6a3+ (trunk:63538, May 22 2008, 17:27:43)
...
>>> import classmeth
>>> classmeth.A.foo
<method 'foo' of 'classmeth.A' objects>
>>> classmeth.A.bar
Segmentation fault

To check that the problem is actually in the new method cache for type
objects, test again clearing the cache:

$ python2.6
Python 2.6a3+ (trunk:63538, May 22 2008, 17:27:43)
...
>>> import classmeth
>>> import sys; sys._clear_type_cache()
>>> classmeth.A.foo
<method 'foo' of 'classmeth.A' objects>
>>> classmeth.A.bar
<built-in method bar of type object at 0x3d9a60>





-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to