On Dec 10, 2007 2:57 PM, Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> wrote: > Dnia 10-12-2007, Pn o godzinie 11:01 -0800, Guido van Rossum pisze: > > > Add a __get__ (instance) method to f's class, and store f directly in > > A. Your __get__ method should return a bound object using > > PyMethod_New(f, a). > > Thank you, but I can't do this, because I want a generic mechanism which > works for an arbitrary f (which will probably be a Kogut object wrapped > in Python, and not all such objects play the role of methods but they > use the same type). > > I solved this by a separate Python type, which is a simple wrapper not > specific to my other types, so I'm a bit surprised that there is no > such type among various wrappers and descriptors in the Python core > (or perhaps I overlooked it somewhere). It wraps a single object f, and > its get_descr(m, obj, type) returns PyMethod_New(f, obj) (for Python3) > or PyMethod_New(f, obj, type) (for Python2), except that if obj == NULL, > it returns f itself. > > It's even better than PyMethod_New(f, NULL, type) in that it does not > need to know the class when created.
I guess there's no such egneric wrapper in the core because the use case hasn't presented itself before -- or nobody thought of creating a generic solution. It's also possible that in the past this was done using unbound methods -- so perhaps their removal from the method object may have been premature. -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com