[Python-3000] removing functions from string module
jcarlson at uci.edu
Wed Apr 18 06:41:49 CEST 2007
"Steven Bethard" <steven.bethard at gmail.com> wrote:
> On 4/17/07, Josiah Carlson <jcarlson at uci.edu> wrote:
> > Christian Heimes <lists at cheimes.de> wrote:
> > > Neal Norwitz schrieb:
> > > > I'm tempted to ask the same thing about the types module.
> > >
> > > Don't forget the 'new' module. It's a candidate for 'svn rm'.
> > >
> > > """Create new objects of various types. Deprecated.
> > >
> > > This module is no longer required except for backward compatibility.
> > > Objects of most types can now be created by calling the type object.
> > > """
> > I would generally agree with you, except that when monkey patching
> > instances...
> > self.method = new.instancemethod(other.method.im_func,
> > self,
> > self.__class__)
> Yes, but you could just as easily write this as::
> self.method = other.method.im_func.__get__(self)
> which I'd contend is better than the original new.instancemethod version.
It is certainly easier to read, but I don't believe it is as
self-documenting as the new.instancemethod variant. What do you get
when calling 'new.instancemethod'? A new instance method.
Is func.__get__ documented anywhere? I've never seen it before (which
is why I use new).
Christian Heimes <lists at cheimes.de> wrote:
> I strongly emphasize on "a bit more". One needs a lot of inside
> knowledge about internal representation to rebind a method to another
> instance. The following idea is much easier to understand:
> self.method = boundmethod(self, method_or_function)
I agree that the above is easier to understand, but boundmethod is not a
builtin in 2.3, 2.4, or 2.5. Even with my own use-case of monkey
patching instances with functions or methods, I would resist its
inclusion as a builtin.
More information about the Python-3000