On Apr 30, 2008, at 6:41 PM, Peter Todd wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1On Wed, Apr 30, 2008 at 06:17:31PM -0700, Robert Bradshaw wrote:On Apr 29, 2008, at 5:42 PM, Peter Todd wrote:Is there a __getattribute__ work-alike in Cython? Essentially I need direct control over an objects tp_getattro and tp_setattro slots to implement a wrapper class. Specificly wrapped.__class__ should go to the wrapped objects class attribute, not the wrapping objects __class__ attribute. __getattr__ outputs C-source that includes a call to PyObject_GenericGetAttr first, and won't run my code if that call succeeds. Thanks, PeterNot that I'm aware of, though I'd imagine that implementing __getattribute__ (if it exists) as being called at the top of this function would be fairly easy to do. One would want to match Python symantics exactly.Thanks for the reply.I've been looking at the Cython source myself, and it looks doable, I'llput some effort into implementing it.
Great!
From what I can see I'd be updating generate_getattro_function() to do a scope.lookup_here() on '__getattribute__' first, if that succeeds, output code to call it, otherwise go on to the existing code.
Sounds like a good plan. Is __getattribute__ inherited?
With the additional complicationthat if __getattribute__ is defined, as well as __getattr__, the lattermust be called if the former raises AttributeError.
Yep, it should go onto the existing code (or call the super/default getattribute) on an error, even if __getattr__ is not defined, to match the specs.
Another question is I noticed that the latest cython-devel code emitswarnings on usage of __new__, saying to use __cinit__ instead. I take itthere is planned work to make __new__ more like Python's __new__ andhave it create the object as well? Again, that's another feature I couldreally use.
Eventually we may implement this (I looked into it some, but it wasn't as straightforward as I had hoped), but using __cinit__ now is good to avoid the confusion.
FWIW I'm writing a electrical design automation library called Tuke. Currently I have some C extension API code written to wrap objects incontexts, but would like to re-write that in Cython as well as implementa whole lot of other basic functionality. http://github.com/retep/tuke/tree/master
Cool. Should I add this to http://wiki.cython.org/projects ? - Robert
PGP.sig
Description: This is a digitally signed message part
_______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
