473,387 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Pyrex problem with cdef'd attribute

I'm using Pyrex 0.9.5.1a. I have this simple Pyrex module:

cdef class Foo:
cdef public char attr

def __init__(self):
self.attr = 0

class Bar(Foo):
def __init__(self):
Foo.__init__(self)
self.attr2 = None

def mod(self):
self.attr = c'B'

f = Bar()
f.mod()

When I run Python and import it an exception is raised:

% python
Python 2.4.2 (#1, Feb 23 2006, 12:48:31)
[GCC 3.4.1] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>import badattr
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "badattr.pyx", line 16, in badattr
f.mod()
File "badattr.pyx", line 13, in badattr.Bar.mod
self.attr = c'B'
TypeError: bad argument type for built-in operation

If the mod() method is defined in the base class it works properly. Is this
a Pyrex bug or am I not allowed to modify cdef'd attributes in subclasses?
(Note that I want Bar visible outside the module, hence no "cdef".)

Thanks,

Skip
Jun 8 '07 #1
3 1479
On Jun 8, 6:00 am, s...@pobox.com wrote:
I'm using Pyrex 0.9.5.1a. I have this simple Pyrex module:
You might get more help on the pyrex list.
cdef class Foo:
cdef public char attr

def __init__(self):
self.attr = 0

class Bar(Foo):
def __init__(self):
Foo.__init__(self)
self.attr2 = None

def mod(self):
self.attr = c'B'

f = Bar()
f.mod()

When I run Python and import it an exception is raised:
Yes, since you didn't cdef the class, it is essentially python code.
Python code cannot assign to a cdef class attribute that is not of
type 'object'
If the mod() method is defined in the base class it works properly. Is this
a Pyrex bug or am I not allowed to modify cdef'd attributes in subclasses?
(Note that I want Bar visible outside the module, hence no "cdef".)
cdef does not affect visibility, IIRC, just whether the class is
compiled into an extension type or not.

This is just from memory though. Greg would be able to give you a
better answer.

-Mike

Jun 8 '07 #2
>I'm using Pyrex 0.9.5.1a. I have this simple Pyrex module:
KlaasYou might get more help on the pyrex list.

Thanks. On the Pyrex website it says that questions are welcome here as
well. I was hoping to avoid yet another mailing list subscription. ;-)

KlaasYes, since you didn't cdef the class, it is essentially python
Klaascode. Python code cannot assign to a cdef class attribute that
Klaasis not of type 'object'

So, if I cdef the Bar subclass I should be okay? I'll play around a bit
more and if I continue to confuse myself will subscribe to the pyrex mailing
list (or at least use the somewhat clunky gmane.org interface).

Skip
Jun 8 '07 #3
sk**@pobox.com wrote:
I'll play around a bit
more and if I continue to confuse myself will subscribe to the pyrex mailing
list (or at least use the somewhat clunky gmane.org interface).
I find that using a newsreader for gmane stuff is far more convenient. I
use Thunderbird to access various infrequently-used mailing lists via
NNTP and Gmane.
--
Michael Hoffman
Jun 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gary Stephenson | last post by:
I'm getting a clean generate, compile and link from my .pyx script, but when I attempt to run the resultant .exe, I get: "The procedure entry point Py_NoneStruct could not be located in the...
10
by: Kyler Laird | last post by:
I need to submit C/C++ code for a class. (It's not a programming class. The choice of language is inertial. I think that it mostly serves to distract students from the course subject.) I'm...
0
by: Chris Lambacher | last post by:
Hi, I have to do some data manipulation that needs to be fast. I had a generator approach (that was faster than a list approch) which was taking approximately 5 seconds to run both encode and...
7
by: Jim Lewis | last post by:
I'm trying to move a function into pyrex for speed. The python side needs to pass a list to the pyrex function. Do I need to convert to array or something so pyrex can generate tight code? I'm not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.