On Oct 23, 2006, at 12:16 AM, William Stein wrote:

> Perhaps there is a fast way to tell whether a class is a Python class 
> or a Pyrex
> class (say in the base class __add__ method), and always call 
> _add_sibling_cdef
> if it's a Pyrex class and _add_sibling if it's a Python class.   There 
> probably
> is, because, e.g., Pyrex classes and Python classes print differently; 
> one prints
> as <type ...> and the other as <class ...>.  I've been looking at the 
> Python/C
> API for a few minutes though and I haven't figured out a fast way to 
> distinguish
> these two.

I think what you've suggested here is the only way to go.

I think there are fast ways to tell, although I haven't tried any of 
these yet. What we could try is examining the associated python type 
object. Its fields are described here:

http://docs.python.org/api/type-structs.html

For example, one promising field is "tp_bases". According to the docs, 
"This is set for types created by a class statement. It should be NULL 
for statically defined types." It looks like Pyrex doesn't set this 
field. So we could write a macro that checks whether this guy is NULL. 
If it's NULL, then it can't be a derived Python type.

David


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to