PyDev – automated refactoring problems
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!.
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'])
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?