AttributeError: 'dict' object has no attribute 'size' when fully qualified

740 views
Skip to first unread message

Jeff Donner

unread,
Apr 17, 2014, 3:11:17 AM4/17/14
to cython...@googlegroups.com
Hi; I can get a C struct to show like I expect when I cimport the symbols into the global namespace, but not when I leave them needing to be fully qualified - can anyone point out what's likely wrong? 

This is with both Cython 19.x, and 20.1.

Thanks.


== Banana.pyx DOESN'T work when symbols have to be fully qualified
cimport cbanana

def add(i):
    cdef cbanana.Banana b
    b.size = i
    cbanana.print_banana(&b)
== test
~/banana> python -c 'import Banana ; Banana.add(5)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "Banana.pyx", line 5, in Banana.add (Banana.c:708)
    b.size = i
AttributeError: 'dict' object has no attribute 'size'


== Banana.pyx WORKS but makes the symbols global
from cbanana cimport Banana, print_banana

def add(i):
    cdef Banana b
    b.size = i
    print_banana(&b)
== test
~/banana> python -c 'import Banana ; Banana.add(5)'
banana 5!


Remaining files:

== banana.h
typedef struct {
  int size;
} Banana;

void print_banana(Banana* b);

== banana-impl.c
#include "banana.h"
#include <stdio.h>

void print_banana(Banana* b) {
  printf("banana %d!\n", b->size);
}

== cbanana.pxd
cdef extern from "banana.h":
    ctypedef struct Banana:
        int size

    void print_banana(Banana* banana)

== setup.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

# build:
#   rm -rf build banana.c Banana.so && \
#   CFLAGS="-I." LDFLAGS="-Llib" python setup.py build_ext -i
# basic test
#   export PYTHONPATH=.
#   python -c 'import Banana ; Banana.add(5)'

setup(name='BananaExtension',
      version='0.1',
      packages=['Banana'],
      package_dir = {'Banana': 'Banana'},
      cmdclass = {'build_ext': build_ext},
      ext_modules=[Extension('Banana',
                             ['Banana.pyx',
                              'banana-impl.c'])
                 ],
     )

Robert Bradshaw

unread,
Apr 17, 2014, 12:35:35 PM4/17/14
to cython...@googlegroups.com
On Thu, Apr 17, 2014 at 12:11 AM, Jeff Donner <jeffrey...@gmail.com> wrote:
Hi; I can get a C struct to show like I expect when I cimport the symbols into the global namespace, but not when I leave them needing to be fully qualified - can anyone point out what's likely wrong? 

This is with both Cython 19.x, and 20.1.

Thanks.

I'm unable to reproduce this. Could you post a complete tarball somewhere?
 

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeff Donner

unread,
Apr 17, 2014, 1:49:15 PM4/17/14
to cython...@googlegroups.com
On Thursday, April 17, 2014 9:35:35 AM UTC-7, Robert Bradshaw wrote:
On Thu, Apr 17, 2014 at 12:11 AM, Jeff Donner <jeffrey...@gmail.com> wrote:
Hi; I can get a C struct to show like I expect when I cimport the symbols into the global namespace, but not when I leave them needing to be fully qualified - can anyone point out what's likely wrong? 

This is with both Cython 19.x, and 20.1.

Thanks.

I'm unable to reproduce this. Could you post a complete tarball somewhere?

It's working for me now, I just wasn't cleaning up the intermediate files correctly. Sorry for the false alarm! 
Jeff
Reply all
Reply to author
Forward
0 new messages