Foundation for Automatic Refactoring Tool#52
Open
MWR27 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This introduces the basic framework for the automatic refactoring tool. It is built upon the included
lib2to3module to allow more powerful static and dynamic transformations. The basic command is as follows:where
sourceis the Python 2 source file or directory to migrate anddestis the directory for the transformed files. The only option available currently is--runor-r, which runssourceas a script or module with the Pygrate warnings. As of now, a warning is collected and stored in a tuple containing the file name, line number, warning type (Py3xorDeprecation), and message; the tuple is now just printed tostdoutto demonstrate. Once we decide how to use the dynamic warnings in the refactoring, we can develop a more sophisticated collection and handling system.Presently, there is only one fixer:
fix_literal_div.py. This converts any division of two integer literals into integer division. While this fixer is only syntactical, I am working on extending the syntactical fixers fromlib2to3to create semantic fixers. These advanced fixers will have access to more context (ProgramContext) of the program. I think the semantic fixers would allow for greater static analysis, and the dynamic Pygrate warnings might be useful in informing the fixers' transformations. I have not implemented a semantic fixer, but the base class (SemanticFix) and instantiation of this kind of fixer is included. TheProgramContextis left stubbed for now until it is needed for implementing a semantic fixer. TheSemanticRefactoringToolwill be the class to handle the semantic fixers. It extendsRefactoringTool, so all of the fixers and functionality fromlib2to3should still work for this automatic refactoring tool.