Turning builtin functions into methods.

Michael Hudson mwh at python.net
Tue Dec 9 10:43:37 EST 2003


Jacek Generowicz <jacek.generowicz at cern.ch> writes:

> Jacek Generowicz <jacek.generowicz at cern.ch> writes:
> 
> > Functions defined in Python have type types.FunctionType, and are
> > descriptors whose __get__ method turns them into bound or unbound
> > methods. Functions defined in extension modules have type
> > types.BuiltinFunctionType, and have no __get__ method. Adding them as
> > attributes to classes and calling them through an instance of the
> > class does not result in them being called as methods: self is lost.
> > 
> > What's the simplest way of getting around this ?
> 
> By trial and error, I seem to have found that passing None as the
> second argument (the instance) to new.instancemethod, does the trick.

PyDescr_NewMethod from C maybe?

> The library reference manual confirms that it is actually supposed to
> work this way. It's a pity that the builtin documentation does not:

The patch manager is over there --->

Cheers,
mwh

-- 
  > With Python you can start a thread, but you can't stop it.  Sorry.
  > You'll have to wait until reaches the end of execution.
  So, just the same as c.l.py, then?
                       -- Cliff Wells & Steve Holden, comp.lang.python




More information about the Python-list mailing list