This is a collection of codemods for Python packages basedon on LibCST.
Codemods are based on LibCST, it will be installed by running:
poetry installTo run the codemods a small shell script mod is provided for convenience:
./mod wxpython.ColorToColourCommand [<source_code_path>, ...]Tests are executed using Pytest which will be installed as dev requirements:
make testList of mods useful for migrating to Mypy.
For each function without a return type adds a default None return type; useful when during the introduction of Mypy a lot of functions are missing the return type and adding it by hand is impratical or inconvenient.
Example of convertion:
def fn f():
passinto:
def f() -> None:
passThese are codemods available to migrate from wxPython 2.8 to 4.x
Converts calls to wx.Color into wx.Colour, i.e.:
wx.Color(255, 255, 255)into:
wx.Colour(255, 255, 255)Renames constants not available anymore into their equivalent in wxPython 4.x, i.e.:
wx.WXK_PRIOR
wx.WXK_NUMPAD_NEXT
wx.FILE_MUST_EXISTinto:
wx.WXK_PAGEUP
wx.WXK_NUMPAD_PAGEDOWN
wx.FD_FILE_MUST_EXISTFix imports of symbols moved into the wx.adv package, i.e.:
import wx
wx.DatePickerCtrl(...)into:
import wx.adv
wx.adv.DatePickerCtrl(...)wx.FlexgridSizer needs now at least 3 arguments and this codemod add the third one with the default value, i.e.:
wx.FlexGridSizer(1, 0)into:
wx.FlexGridSizer(1, 0, 0)Renames keywords, like help into helpString, and renames the wx.Menu.AppendItem method into wx.Menu.Append if called with a single argument, i.e.:
menu.AppendItem(menu_item)
menu.Append(
help="",
id=1,
kind=wx.ITEM_NORMAL,
text="Menu item",
)into :
menu.Append(menu_item)
menu.Append(
helpString="",
id=1,
kind=wx.ITEM_NORMAL,
item="Menu item",
)Renames calls to wx.Toolbar.DoAddTool into wx.Toolbar.AddTool, i.e.:
toolbar.DoAddTool(
bitmap=my_bitmap,
id=1,
label="Toolbar tool"
)into:
toolbar.AddTool(
bitmap=my_bitmap,
toolId=1,
label="Toolbar tool"
)Renames calls to wx.Sizer.AddWindow into wx.Sizer.Add, i.e.:
sizer.AddWindow(panel, 0, border=0, flag=wx.EXPAND)into:
sizer.Add(panel, 0, border=0, flag=wx.EXPAND)Renames calls to wx.ListCtrl.InsertColumnInfo into wx.ListCtrl.InsertColumn, i.e.:
list_ctrl.InsertColumnInfo(0, info)into:
list_ctrl.InsertColumn(0, info)Replaces all the deprecated symbols and methods with the eqivalent in wxPython 4.x, i.e.:
wx.BitmapFromImage()
wx.DateTimeFromDMY(*args)into :
wx.Bitmap()
wx.DateTime.FromDMY(*args)The wx.Frame.MakeModal method has been removed and wxPython 4.x suggest to use a modal dialog instead, however for previous code to continue to work this codemod adds an artigicial MakeModal method to any class which calls self.MakeModal() in the code, i.e.:
class MyModal(wx.Frame):
def __init__(self):
super().__init__()
self.MakeModal()into:
class MyModal(wx.Frame):
def __init__(self):
super().__init__()
self.MakeModal()
def MakeModal(self, modal=True):
if modal and not hasattr(self, '_disabler'):
self._disabler = wx.WindowDisabler(self)
if not modal and hasattr(self, '_disabler'):
del self._disabler