#573 Please add implement method to refactoring menu

closed-works-for-me
nobody
5
2012-03-27
2012-03-27
Luke
No

This would be similar to extract method except that it woud infer the type and add the method to that class.

For example:

If I had an unimplemented method as follows:

instanceOfClassA.unimplementedMethod(param1, param2)

When I used the refactoringing I would get this:

class ClassA(object):

def unimplementedMethod(param1, param2)
pass

Additionally it would be nice if it notice that a value was being returned and put in a return statement

Discussion

  • Luke
    Luke
    2012-03-27

    Please delete, this was an accident

     
  • Fabio Zadrozny
    Fabio Zadrozny
    2012-03-27

    • status: open --> closed-duplicate
     
  • Luke
    Luke
    2012-03-27

    • status: closed-duplicate --> open
     
  • Luke
    Luke
    2012-03-27

    Your proposed solutiuons do not work. First this is a base class. Second this class implemented in a different file.

    In my case I am doing Test Driven Development and I have two files. 1. For the class. 2. For the tests.

    In the test file I have something like this:

    class ClassA_Test(unittest.TestCase):
    def test_canCallUnimplementedMethod(self):
    instanceOfClassA = ClassA
    instanceOfClassA.unimplementedMethod(param1, param2)
    self.assertEquals(1, instanceOfClassA.unimplementedMethodCalled)
    pass
    --------
    in the class file I have:

    class ClassA(object):
    '''
    classdocs
    '''

    def __init__(self):
    '''
    Constructor
    '''
    -----
    The test of course fails and I select the method in the test file and try your proposed solutions. First, I am only able to override or implement methods of the class unittest.TestCase NOT of ClassA. Second, since I am not override a base class, your alternate solution is not even avaliable. What I would expect is to have the method prototype created in the class file as described above.

    -----------------------
    Actually, that's already available in 2 ways:

    You can either: select a given class, right click > refactoring >
    override/implement methods (in the menu, the shortcut for it will appear).

    Another option would be in the derived class method, request a
    code-completion right after the 'def'.

    I.e.:

    class A:
    ..def method(self):
    ....pass

    class B(A):
    ..def <- request code completion here and it should show the list of
    methods to override.

     
  • Fabio Zadrozny
    Fabio Zadrozny
    2012-03-27

    Ok, I misunderstood the issue... what you want is available by hitting ctrl+1 in that line and choosing the option to do the method.

    There's a screencast featuring that at: http://pydev.org/video_pydev_20.html

    -- hope I got it right this time :)

     
  • Fabio Zadrozny
    Fabio Zadrozny
    2012-03-27

    • status: open --> closed-works-for-me