Lisandro Dalcin wrote: > On Fri, Mar 13, 2009 at 12:46 PM, Stefan Behnel wrote: >> Carl Witty wrote: >>> Hmm... I hope that eventually Cython will allow overriding __new__, at >>> which point calling an extension type won't necessarily return a value >>> of that type. >> >> I'm not sure. This should certainly be supported for Python classes, but >> for extension types? What would be the use case? > > Well, take for granted that if this were available, I would use it in > mpi4py. > > For example, some instances of cdef classes could be specially > handled, and I could easily implement things like in the code below: > > comm = MPI.Comm(MPI.COMM_WORLD) > assert comm is MPI.COMM_WORLD > > and the assertion will succeed...
Am I right in guessing that Comm is an extension type here and that COMM_WORLD is an instance? So you want to use Comm as both a class and a factory, right? So, what was your use case again? > Moreover, any cdef class whose instances are intended to be immutable > (like int, str, float, tuple) could benefit from this feature, such in > the same way that core CPython does. Here, I assume you are hinting towards singletons and caching, right? lxml actually does this with dedicated factories, but I can see that some APIs may benefit from such a behaviour. So, can't we just require that ExtType.__new__() returns an instance of ExtType (or its subtypes)? Or is there a use case that would benefit from returning arbitrary things? Stefan _______________________________________________ Cython-dev mailing list Cython-dev@codespeak.net http://codespeak.net/mailman/listinfo/cython-dev