-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 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,
> >
> >Peter
> 
> Not 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'll
put some effort into implementing it. 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. With the additional complication
that if __getattribute__ is defined, as well as __getattr__, the latter
must be called if the former raises AttributeError.


Another question is I noticed that the latest cython-devel code emits
warnings on usage of __new__, saying to use __cinit__ instead. I take it
there is planned work to make __new__ more like Python's __new__ and
have it create the object as well? Again, that's another feature I could
really use.


FWIW I'm writing a electrical design automation library called Tuke.
Currently I have some C extension API code written to wrap objects in
contexts, but would like to re-write that in Cython as well as implement
a whole lot of other basic functionality.

http://github.com/retep/tuke/tree/master

- -- 
http://petertodd.org 'peter'[:[EMAIL PROTECTED] 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIGR+z3bMhDbI9xWQRAjUsAKCx7XeM/+KRs9vCA3+XUuundIfF0wCfRJcf
nH3ByGq6MPaRUktCxWho5KE=
=oz0w
-----END PGP SIGNATURE-----
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to