Skip to content

Commit

Permalink
style: Fixes some unnecessary-lambda (PLW0108)
Browse files Browse the repository at this point in the history
Concerns Pylint rule "unnecessary-lambda / W0108"

Using `ruff check --output-format=concise --select PLW0108 --preview --fix --unsafe-fixes`.

Didn't apply to cases where it wasn't clear if it was safe
  • Loading branch information
echoix committed Jun 30, 2024
1 parent 3738001 commit 44b75f5
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 76 deletions.
2 changes: 1 addition & 1 deletion gui/wxpython/animation/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def OnPreferences(self, event):
if not self.dialogs["preferences"]:
dlg = PreferencesDialog(parent=self, giface=self._giface)
self.dialogs["preferences"] = dlg
dlg.formatChanged.connect(lambda: self.controller.UpdateAnimations())
dlg.formatChanged.connect(self.controller.UpdateAnimations)
dlg.CenterOnParent()

self.dialogs["preferences"].Show()
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/gmodeler/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ def __init__(
parent=self, giface=giface, menuModel=menuModel.GetModel()
)
self.cmd_prompt.promptRunCmd.connect(self.OnCommand)
self.cmd_prompt.commandSelected.connect(
lambda command: self.label.SetValue(command)
)
self.cmd_prompt.commandSelected.connect(self.label.SetValue)
self.search = SearchModuleWidget(
parent=self.panel, model=menuModel.GetModel(), showTip=True
)
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/gmodeler/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ def __init__(
self.goutput = GConsoleWindow(
parent=self, giface=giface, gconsole=self._gconsole
)
self.goutput.showNotification.connect(
lambda message: self.SetStatusText(message)
)
self.goutput.showNotification.connect(self.SetStatusText)

# here events are binded twice
self._gconsole.Bind(
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/gui_core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,7 @@ def __init__(
self._gconsole.mapCreated.connect(self.OnMapCreated)
self.goutput = self.notebookpanel.goutput
if self.goutput:
self.goutput.showNotification.connect(
lambda message: self.SetStatusText(message)
)
self.goutput.showNotification.connect(self.SetStatusText)

self.notebookpanel.OnUpdateValues = self.updateValuesHook
guisizer.Add(self.notebookpanel, proportion=1, flag=wx.EXPAND)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gui_core/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def __init__(self, parent, handlerObj, giface, model, id=wx.ID_ANY, **kwargs):
self._btnAdvancedSearch.Bind(wx.EVT_BUTTON, lambda evt: self.AdvancedSearch())

self._tree.selectionChanged.connect(self.OnItemSelected)
self._tree.itemActivated.connect(lambda node: self.Run(node))
self._tree.itemActivated.connect(self.Run)

self._layout()

Expand Down
8 changes: 3 additions & 5 deletions gui/wxpython/gui_core/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,9 @@ def __init__(self, parent, giface, menuModel, margin=False):
self._loadHistory()
if giface:
giface.currentMapsetChanged.connect(self._loadHistory)
giface.entryToHistoryAdded.connect(
lambda entry: self._addEntryToCmdHistoryBuffer(entry)
)
giface.entryToHistoryAdded.connect(self._addEntryToCmdHistoryBuffer)
giface.entryFromHistoryRemoved.connect(
lambda index: self._removeEntryFromCmdHistoryBuffer(index)
self._removeEntryFromCmdHistoryBuffer
)
#
# bindings
Expand Down Expand Up @@ -433,7 +431,7 @@ def GetWordLeft(self, withDelimiter=False, ignoredDelimiter=None):
else:
delimiter = char
parts.append(delimiter + textLeft.rpartition(char)[2])
return min(parts, key=lambda x: len(x))
return min(parts, key=len)

def ShowList(self):
"""Show sorted auto-completion list if it is not empty"""
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gui_core/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ def _searchModule(self, keys, value):
nodes.update(self._model.SearchNodes(key=key, value=value))

nodes = list(nodes)
nodes.sort(key=lambda node: self._model.GetIndexOfNode(node))
nodes.sort(key=self._model.GetIndexOfNode)
self._results = nodes
self._resultIndex = -1
commands = sorted(
Expand Down
8 changes: 2 additions & 6 deletions gui/wxpython/history/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,8 @@ def __init__(
self.runIgnoredCmdPattern = Signal("HistoryBrowserTree.runIgnoredCmdPattern")

self._giface.currentMapsetChanged.connect(self.UpdateHistoryModelFromScratch)
self._giface.entryToHistoryAdded.connect(
lambda entry: self.InsertCommand(entry)
)
self._giface.entryInHistoryUpdated.connect(
lambda entry: self.UpdateCommand(entry)
)
self._giface.entryToHistoryAdded.connect(self.InsertCommand)
self._giface.entryInHistoryUpdated.connect(self.UpdateCommand)

self.SetToolTip(_("Double-click to open the tool"))
self.selectionChanged.connect(self.OnItemSelected)
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/iclass/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ def __init__(
# TODO: for vdigit: it does nothing here because areas do not produce
# this info
self.firstMapWindow.digitizingInfo.connect(
lambda text: self.statusbarManager.statusbarItems[
"coordinates"
].SetAdditionalInfo(text)
self.statusbarManager.statusbarItems["coordinates"].SetAdditionalInfo
)
self.firstMapWindow.digitizingInfoUnavailable.connect(
lambda: self.statusbarManager.statusbarItems[
Expand Down
20 changes: 5 additions & 15 deletions gui/wxpython/lmgr/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,7 @@ def _createNotebook(self):
def _createDataCatalog(self, parent):
"""Initialize Data Catalog widget"""
self.datacatalog = DataCatalog(parent=parent, giface=self._giface)
self.datacatalog.showNotification.connect(
lambda message: self.SetStatusText(message)
)
self.datacatalog.showNotification.connect(self.SetStatusText)

def _createDisplay(self, parent):
"""Initialize Display widget"""
Expand All @@ -412,9 +410,7 @@ def _createSearchModule(self, parent):
giface=self._giface,
model=self._moduleTreeBuilder.GetModel(),
)
self.search.showNotification.connect(
lambda message: self.SetStatusText(message)
)
self.search.showNotification.connect(self.SetStatusText)
else:
self.search = None

Expand All @@ -434,9 +430,7 @@ def _createConsole(self, parent):
menuModel=self._moduleTreeBuilder.GetModel(),
gcstyle=GC_PROMPT,
)
self.goutput.showNotification.connect(
lambda message: self.SetStatusText(message)
)
self.goutput.showNotification.connect(self.SetStatusText)

self._gconsole.mapCreated.connect(self.OnMapCreated)
self._gconsole.Bind(
Expand All @@ -449,9 +443,7 @@ def _createHistoryBrowser(self, parent):
"""Initialize history browser widget"""
if not UserSettings.Get(group="manager", key="hideTabs", subkey="history"):
self.history = HistoryBrowser(parent=parent, giface=self._giface)
self.history.showNotification.connect(
lambda message: self.SetStatusText(message)
)
self.history.showNotification.connect(self.SetStatusText)
self.history.runIgnoredCmdPattern.connect(
lambda cmd: self.RunSpecialCmd(command=cmd),
)
Expand Down Expand Up @@ -637,9 +629,7 @@ def _addPagesToNotebook(self):

# add 'console' widget to main notebook page and add connect switch page signal
self.notebook.AddPage(page=self.goutput, text=_("Console"), name="output")
self.goutput.contentChanged.connect(
lambda notification: self._switchPage(notification)
)
self.goutput.contentChanged.connect(self._switchPage)

# add 'history module' widget to main notebook page
if self.history:
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/lmgr/layertree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ def OnPopupGroupOpacityLevel(self, event):
lambda value: self.ChangeGroupLayerOpacity(layer=child, value=value)
)
# Apply button
dlg.applyOpacity.connect(lambda: self._recalculateLayerButtonPosition())
dlg.applyOpacity.connect(self._recalculateLayerButtonPosition)
dlg.CentreOnParent()

if dlg.ShowModal() == wx.ID_OK:
Expand Down Expand Up @@ -1288,7 +1288,7 @@ def OnPopupOpacityLevel(self, event):
)
)
# Apply button
dlg.applyOpacity.connect(lambda: self._recalculateLayerButtonPosition())
dlg.applyOpacity.connect(self._recalculateLayerButtonPosition)
dlg.CentreOnParent()

if dlg.ShowModal() == wx.ID_OK:
Expand Down
20 changes: 5 additions & 15 deletions gui/wxpython/main_window/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,7 @@ def _createMainNotebook(self):
def _createDataCatalog(self, parent):
"""Initialize Data Catalog widget"""
self.datacatalog = DataCatalog(parent=parent, giface=self._giface)
self.datacatalog.showNotification.connect(
lambda message: self.SetStatusText(message)
)
self.datacatalog.showNotification.connect(self.SetStatusText)

def _createDisplay(self, parent):
"""Initialize Display widget"""
Expand All @@ -355,9 +353,7 @@ def _createSearchModule(self, parent):
giface=self._giface,
model=self._moduleTreeBuilder.GetModel(),
)
self.search.showNotification.connect(
lambda message: self.SetStatusText(message)
)
self.search.showNotification.connect(self.SetStatusText)
else:
self.search = None

Expand All @@ -377,12 +373,8 @@ def _createConsole(self, parent):
menuModel=self._moduleTreeBuilder.GetModel(),
gcstyle=GC_PROMPT,
)
self.goutput.showNotification.connect(
lambda message: self.SetStatusText(message)
)
self.goutput.contentChanged.connect(
lambda notification: self._focusPage(notification)
)
self.goutput.showNotification.connect(self.SetStatusText)
self.goutput.contentChanged.connect(self._focusPage)

self._gconsole.mapCreated.connect(self.OnMapCreated)
self._gconsole.Bind(
Expand All @@ -395,9 +387,7 @@ def _createHistoryBrowser(self, parent):
"""Initialize history browser widget"""
if not UserSettings.Get(group="manager", key="hideTabs", subkey="history"):
self.history = HistoryBrowser(parent=parent, giface=self._giface)
self.history.showNotification.connect(
lambda message: self.SetStatusText(message)
)
self.history.showNotification.connect(self.SetStatusText)
self.history.runIgnoredCmdPattern.connect(
lambda cmd: self.RunSpecialCmd(command=cmd),
)
Expand Down
12 changes: 3 additions & 9 deletions gui/wxpython/mapdisp/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ def _addToolbarVDigit(self):
)
self._setUpMapWindow(self.MapWindowVDigit)
self.MapWindowVDigit.digitizingInfo.connect(
lambda text: self.statusbarManager.statusbarItems[
"coordinates"
].SetAdditionalInfo(text)
self.statusbarManager.statusbarItems["coordinates"].SetAdditionalInfo
)
self.MapWindowVDigit.digitizingInfoUnavailable.connect(
lambda: self.statusbarManager.statusbarItems[
Expand Down Expand Up @@ -366,9 +364,7 @@ def _addToolbarVDigit(self):
def openATM(selection):
self._layerManager.OnShowAttributeTable(None, selection=selection)

self.toolbars["vdigit"].openATM.connect(
lambda selection: openATM(selection)
)
self.toolbars["vdigit"].openATM.connect(openATM)
self.Map.layerAdded.connect(self._updateVDigitLayers)
self.MapWindowVDigit.SetToolbar(self.toolbars["vdigit"])

Expand Down Expand Up @@ -1247,9 +1243,7 @@ def _onMeasure(self, controller):
self.measureController = controller(self._giface, mapWindow=self.GetMapWindow())
# assure that the mode is ended and lines are cleared whenever other
# tool is selected
self._toolSwitcher.toggleToolChanged.connect(
lambda: self.measureController.Stop()
)
self._toolSwitcher.toggleToolChanged.connect(self.measureController.Stop)
self.measureController.Start()

def OnProfile(self, event):
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/mapdisp/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ def CreateMapDisplay(self, name, decorations=True):
),
)

self.Map.saveToFile.connect(lambda cmd: self.mapDisplay.DOutFile(cmd))
self.Map.dToRast.connect(lambda cmd: self.mapDisplay.DToRast(cmd))
self.Map.saveToFile.connect(self.mapDisplay.DOutFile)
self.Map.dToRast.connect(self.mapDisplay.DToRast)
self.Map.query.connect(
lambda ltype, maps: self.mapDisplay.SetQueryLayersAndActivate(
ltype=ltype, maps=maps
Expand Down
8 changes: 3 additions & 5 deletions gui/wxpython/mapswipe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def __init__(
self.secondMapWindow.mapQueried.connect(self.Query)

# bind tracking cursosr to mirror it
self.firstMapWindow.Bind(wx.EVT_MOTION, lambda evt: self.TrackCursor(evt))
self.secondMapWindow.Bind(wx.EVT_MOTION, lambda evt: self.TrackCursor(evt))
self.firstMapWindow.Bind(wx.EVT_MOTION, self.TrackCursor)
self.secondMapWindow.Bind(wx.EVT_MOTION, self.TrackCursor)

self.MapWindow = self.firstMapWindow # current by default
self.firstMapWindow.zoomhistory = self.secondMapWindow.zoomhistory
Expand Down Expand Up @@ -785,9 +785,7 @@ def Query(self, x, y):
else:
self._queryDialog = QueryDialog(parent=self, data=result)
self._queryDialog.Bind(wx.EVT_CLOSE, self._oncloseQueryDialog)
self._queryDialog.redirectOutput.connect(
lambda output: self._giface.WriteLog(output)
)
self._queryDialog.redirectOutput.connect(self._giface.WriteLog)
self._queryDialog.Show()

def _oncloseQueryDialog(self, event):
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/rdigit/g.gui.rdigit.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def __init__(
rdigit.OnMapSelection()
# use Close instead of QuitRDigit for standalone tool
self.rdigit.quitDigitizer.disconnect(self.QuitRDigit)
self.rdigit.quitDigitizer.connect(lambda: self.Close())
self.rdigit.quitDigitizer.connect(self.Close)

# add Map Display panel to Map Display frame
sizer = wx.BoxSizer(wx.VERTICAL)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/vdigit/g.gui.vdigit.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self, parent, vectorMap):
self.toolbars["vdigit"].StartEditing(mapLayer)
# use Close instead of QuitVDigit for standalone tool
self.toolbars["vdigit"].quitDigitizer.disconnect(self.QuitVDigit)
self.toolbars["vdigit"].quitDigitizer.connect(lambda: self.Close())
self.toolbars["vdigit"].quitDigitizer.connect(self.Close)

# add Map Display panel to Map Display frame
sizer = wx.BoxSizer(wx.VERTICAL)
Expand Down

0 comments on commit 44b75f5

Please sign in to comment.