Lisandro Dalcin, 27.08.2010 23:38: >> I think the right way to implement this is with custom decriptors for both >> the type and its instance. > > Do you mean adding a descriptor for __dict__ ? If you use cdef > public|readonly __dict__, you get it.
Right, I think __dict__ should be "public" by default, just like __weakref__ is always usable from outside. > But Cython code will make a > direct pointer access, like for any other cdef member... What's wrong > with this approach? Well, it wastes instance memory if __dict__ is not used. I would expect that most use cases for __dict__ do not come from Cython code but from Python code that uses the types. As I said, going through a descriptor would allow instantiating the dict at first request rather than *always*. That's important for library code. Potentially, we could also add a NULL check in the Cython access code wherever __dict__ is used, and go through the descriptor only if it's not set up yet. But that would be an optimisation. I think safe and memory friendly access should go first. > The only > improvement I can imagine right now is to hack on type inference to > attach 'dict' type to __dict__ regardless of the user declaration, my > patch does not includes that just because I do not know how to > implement the feature. Yes, I think it makes sense to always infer 'dict', especially when we go through the tp_dict* slots directly. Stefan _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
