Wing Tips: Moving Code with Refactoring in Wing Pro

Aug 19, 2019

In this issue of Wing Tips we explain how to quickly move functions, methods, classes, and other symbols around in Python code, using Wing Pro's Move Symbol refactoring operation.

This operation takes care of updating all the points of reference for the symbol that is being moved. For example, if a function is moved from one module to another then Wing will update all the points of call for that function to import the module it has been moved into and invoke the function from there.


Here's a simple example that moves a class from one file to another:


Shown Above: Right-click to initiate Move Symbol, select target location, execute the move operation, select the moved function, and then select the added import statement.

Notice that Wing adds the necessary import testtarget to and changes the two places where the class MyTestClass is used to reference the class in its new location in Using refactoring is much easier and less prone to errors than making edits of this type manually.

Try It Yourself

You can easily try this out in your copy of Wing Pro, by selecting any symbol in your Python code base, and choosing Move Symbol from the Refactor menu. As in the above example, you will be asked to choose the target location for the move, which can either be the top level of any module, or within a class or def. An unwanted move can be backed out with the Revert button in the Refactoring tool.

That's it for now! We'll be back soon with more Wing Tips for Wing Python IDE.

Share this article: