rope
rope copied to clipboard
Convert a Function to a Method Feature Request
Hey,
I think a lot of developers would benefit from the ability to move an arbitrary function to a class as a method, and break it down inside the class, in addition one should be able to choose to one of the following behaviors:
- the class is initialized by an arg-less constructor
- the class is initialized by a factory method
- the method is a staticmethod
- the method is a classmethod
Reference: http://refactoring.com/catalog/replaceMethodWithMethodObject.html
What do you think? (I'm more than willing to implement this feature :)
Additional acceptance criteria:
- [ ] update documentation
Gal Vinograd [email protected] wrote:
I think a lot of developers would benefit from the ability to move an arbitrary function to a class as a method, and break it down inside the class, in addition one should be able to choose to one of the following behaviors:
- the class is initialized by the ctor
- the class is initialized by a factory method
- the method is a staticmethod
- the method is a classmethod
What do you think? (I'm more willing to implement this feature :)
It does seem interesting. I wonder how much of this can be done right now with the inline method refactoring. For instance:
class C(object):
pass
def func(a):
return a * 2
Can be transformed into
class C(object):
@staticmethod
def func(a):
return a * 2
def func(a):
C.func(a)
And performing inline method on the global func().
Ali
It sounds like the right way, I'll start implementing in the next few days :)
Closing as duplicate of #371.
Edit: Hmmm... actually, on a second read, this doesn't seem to be a duplicate.