PyDev – automated refactoring problems

Béres Botond

Update: This has been resolved in PyDev 2.2.1!

My usual development tool for Python and Django projects is Eclipse + PyDev. This combination is pretty powerful, I’ve been using it for a long time and I like it, but there are some pain points that I wish would be improved upon.

For example PyDev’s automated refactoring support could use some improvement. I’ve just noticed the following “fail” when applying Extract Local Variable on some instance variable data like self.data['0']['values'] below. After extracting and assigning it to a local variable, it will just rename the first occurrence of self.data['0']['values'], in the same function!.

Before

def do_something(self):
 self.instance_method(self.data['0']['values'])
 
 ...
 
 self.another_instance_method(self.data['0']['values'])
 self.yet_another_instance_method(self.data['0']['values'])

After

def do_something(self):
 values_node = self.data['0']['values']
 self.instance_method(values_node)
 
 ...
 
 self.another_instance_method(self.data['0']['values'])
 self.yet_another_instance_method(self.data['0']['values'])

Now I understand that the reason for this must be that we are talking about an instance variable. PyDev cannot know for sure if in the section we modify the value of our instance variable indirectly or not. Or maybe another_instance_method modifies/overwrites it and then replacing all occurences would be a bad idea. Of course changing instance variables like that is a very bad practice but PyDev cannot know if we are using best practices or not in our code logic, so it stays on the safe side.

However, when doing the Extract Local Variable refactoring, it would be simple to have an option of  also replacing all occurrences or not. Let the programmer decide! I believe that’s the correct solution in this case and exactly what PyCharm does in this situation. So that’s a +1 point to PyCharm for this. I realize this is just one small bonus point to PyCharm, I’ve been playing around with it for some time and looks like a really nice IDE, but I’m not quite convinced yet if it’s completely superior to Eclipse + PyDev. We’ll see …

Which one do you like better? Or what other IDE are you using and how does it compare to Pydev/PyCharm?


3 Responses to “PyDev – automated refactoring problems”

  • Fabio Zadrozny Says:

    Hi Béres,

    Thanks for the report related to PyDev (won’t be added in the next release, but please keep an eye on it as that change was already planned for some time and it’s already close to being tackled — probably 2 releases from now).

    Cheers,

    Fabio

    • Béres Botond Says:

      Hi Fabio,

      Thanks for the feedback, I’m glad to hear this is already being looked at. Pydev is certainly a great plugin and just getting better constantly, keep up the good work!

  • Fabio Zadrozny Says:

    Hi Béres,

    It ended up getting there in the latest PyDev release (2.2.1).

    Cheers,

    Fabio

Leave a Reply