Skip to content

Foundation for Automatic Refactoring Tool#52

Open
MWR27 wants to merge 1 commit into
softdevteam:migrationfrom
MWR27:autorefactor
Open

Foundation for Automatic Refactoring Tool#52
MWR27 wants to merge 1 commit into
softdevteam:migrationfrom
MWR27:autorefactor

Conversation

@MWR27

@MWR27 MWR27 commented Jul 14, 2026

Copy link
Copy Markdown

This introduces the basic framework for the automatic refactoring tool. It is built upon the included lib2to3 module to allow more powerful static and dynamic transformations. The basic command is as follows:

pygrate2 [options] source dest

where source is the Python 2 source file or directory to migrate and dest is the directory for the transformed files. The only option available currently is --run or -r, which runs source as 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 (Py3x or Deprecation), and message; the tuple is now just printed to stdout to 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 from lib2to3 to 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. The ProgramContext is left stubbed for now until it is needed for implementing a semantic fixer. The SemanticRefactoringTool will be the class to handle the semantic fixers. It extends RefactoringTool, so all of the fixers and functionality from lib2to3 should still work for this automatic refactoring tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant