Skip to content

Commit

Permalink
style: Fix implicit-return-value (RET502)
Browse files Browse the repository at this point in the history
RET502: Do not implicitly `return None` in function able to return non-`None` value

Ruff rule: https://docs.astral.sh/ruff/rules/implicit-return-value/
  • Loading branch information
echoix committed Feb 2, 2025
1 parent 09f9235 commit f533f55
Show file tree
Hide file tree
Showing 31 changed files with 54 additions and 55 deletions.
2 changes: 1 addition & 1 deletion gui/wxpython/animation/nviztask.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def GetCommandSeries(self, layerList, paramName):

if len(layerList) > 1:
raise GException(_("Please add only one layer in the list."))
return
return None
layer = layerList[0]
if hasattr(layer, "maps"):
series = layer.maps
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/gcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def __del__(self):
def run(self):
"""Run command"""
if len(self.cmd) == 0:
return
return None

Debug.msg(1, "gcmd.CommandThread(): %s" % " ".join(self.cmd))

Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ def SaveToFile(self, settings=None):
os.mkdir(dirPath)
except OSError:
GError(_("Unable to create settings directory"))
return
return None
try:
with open(self.filePath, "w") as f:
json.dump(settings, f, indent=2, cls=SettingsJSONEncoder)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/dbmgr/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def LoadData(self, layer, columns=None, where=None, sql=None):
)
% {"column": col, "table": tableName},
)
return
return None

try:
# for maps connected via v.external
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/gcp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,7 @@ def GetNewExtent(self, region, map=None):

if not self.CheckGCPcount(msg=True):
self.gr_order = order
return
return None

self.gr_order = order

Expand Down Expand Up @@ -2152,7 +2152,7 @@ def GetNewExtent(self, region, map=None):
"Could not calculate new extends.\nPossible error with m.transform."
),
)
return
return None

# fist corner
e, n = errlist[0].split()
Expand Down Expand Up @@ -2492,7 +2492,7 @@ def AddGCPItem(self):
def DeleteGCPItem(self):
"""Deletes selected item in GCP list."""
if self.selected == wx.NOT_FOUND:
return
return None

key = self.GetItemData(self.selected)
self.DeleteItem(self.selected)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gmodeler/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _layout(self):
def GetType(self):
"""Get element type"""
if not self.etype:
return
return None
return self.element.tcp.GetType()

def OnType(self, event):
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gui_core/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def CreateNewVector(
% outmap,
)
dlg.Destroy()
return
return None

if outmap == "": # should not happen
dlg.Destroy()
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/gui_core/gselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2086,7 +2086,7 @@ def GetDsn(self):
)
if not ret:
GError(parent=self, message=message)
return
return None

connection_string = None
for conn in ret.splitlines():
Expand All @@ -2107,7 +2107,7 @@ def GetDsn(self):
return connection_string
if not connection_string:
GError(parent=self, message=message)
return
return None
else:
name = self._getCurrentDbWidgetName()
if name == "choice":
Expand Down
10 changes: 5 additions & 5 deletions gui/wxpython/iclass/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def ImportAreas(self, vector):
warning = self._checkImportedTopo(vector)
if warning:
GMessage(parent=self, message=warning)
return
return None

wx.BeginBusyCursor()
wx.GetApp().Yield()
Expand All @@ -698,7 +698,7 @@ def ImportAreas(self, vector):
# open vector map to be imported
if digitClass.OpenMap(vector, update=False) is None:
GError(parent=self, message=_("Unable to open vector map <%s>") % vector)
return
return None

# copy features to the temporary map
vname = self._getTempVectorName()
Expand All @@ -709,7 +709,7 @@ def ImportAreas(self, vector):
parent=self,
message=_("Unable to copy vector features from <%s>") % vector,
)
return
return None
del os.environ["GRASS_VECTOR_TEMPORARY"]

# close map
Expand All @@ -719,7 +719,7 @@ def ImportAreas(self, vector):
self.poMapInfo = digitClass.OpenMap(vname, tmp=True)
if self.poMapInfo is None:
GError(parent=self, message=_("Unable to open temporary vector map"))
return
return None

# remove temporary rasters
for cat in self.stats_data.GetCategories():
Expand Down Expand Up @@ -1119,7 +1119,7 @@ def RunAnalysis(self):
Signatures are created but signature file is not.
"""
if not self.CheckInput(group=self.g["group"], vector=self.trainingAreaVector):
return
return None

for statistic in self.cStatisticsDict.values():
I_iclass_free_statistics(statistic)
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/image2target/ii2t_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,7 @@ def GetNewExtent(self, region, map=None):

if not self.CheckGCPcount(msg=True):
self.gr_order = order
return
return None

self.gr_order = order

Expand Down Expand Up @@ -2103,7 +2103,7 @@ def GetNewExtent(self, region, map=None):
"Possible error with i.ortho.transform."
),
)
return
return None

# fist corner
e, n = errlist[0].split()
Expand Down Expand Up @@ -2449,7 +2449,7 @@ def AddGCPItem(self):
def DeleteGCPItem(self):
"""Deletes selected item in GCP list."""
if self.selected == wx.NOT_FOUND:
return
return None

key = self.GetItemData(self.selected)
self.DeleteItem(self.selected)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/iscatt/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _deactivateMode(self):
def GetCoords(self):
coords = self.polygon_drawer.GetCoords()
if coords is None:
return
return None

if self.transpose:
for c in coords:
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/lmgr/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ def OnRunScript(self, event):
message=_("Script file '%s' doesn't exist. Operation canceled.")
% filename,
)
return
return None

# check permission
if not os.access(filename, os.X_OK):
Expand All @@ -1246,14 +1246,14 @@ def OnRunScript(self, event):
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
)
if dlg.ShowModal() != wx.ID_YES:
return
return None
dlg.Destroy()
try:
mode = stat.S_IMODE(os.lstat(filename)[stat.ST_MODE])
os.chmod(filename, mode | stat.S_IXUSR)
except OSError:
GError(_("Unable to set permission. Operation canceled."), parent=self)
return
return None

# check GRASS_ADDON_PATH
addonPath = os.getenv("GRASS_ADDON_PATH", [])
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/lmgr/layertree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ def AddLayer(
if self.GetLayerInfo(item, key="type") == "vector":
name = self.GetLayerInfo(item, key="maplayer").GetName()
if name == lname:
return
return None
item = self.GetNextItem(item)

selectedLayer = self.GetSelectedLayer()
Expand Down
8 changes: 4 additions & 4 deletions gui/wxpython/location_wizard/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,7 @@ def OnPageChanging(self, event: WizardEvent):
if event.GetDirection():
if not self.epsgcode:
event.Veto()
return
return None
# check for datum transforms
ret = RunCommand(
"g.proj", read=True, epsg=self.epsgcode, datum_trans="-1", flags="t"
Expand Down Expand Up @@ -1882,7 +1882,7 @@ def OnPageChanging(self, event: WizardEvent):
if event.GetDirection():
if not self.epsgcode:
event.Veto()
return
return None
# check for datum transforms
ret = RunCommand(
"g.proj",
Expand Down Expand Up @@ -2089,7 +2089,7 @@ def OnPageChanging(self, event: WizardEvent):

if self.customstring.find("+datum=") < 0:
self.GetNext().SetPrev(self)
return
return None

# check for datum transforms
# FIXME: -t flag is a hack-around for trac bug #1849
Expand All @@ -2109,7 +2109,7 @@ def OnPageChanging(self, event: WizardEvent):
style=wx.OK | wx.ICON_ERROR | wx.CENTRE,
)
event.Veto()
return
return None

if out:
dtrans = ""
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/main_window/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ def OnRunScript(self, event):
message=_("Script file '%s' doesn't exist. Operation canceled.")
% filename,
)
return
return None

# check permission
if not os.access(filename, os.X_OK):
Expand All @@ -1401,14 +1401,14 @@ def OnRunScript(self, event):
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
)
if dlg.ShowModal() != wx.ID_YES:
return
return None
dlg.Destroy()
try:
mode = stat.S_IMODE(os.lstat(filename)[stat.ST_MODE])
os.chmod(filename, mode | stat.S_IXUSR)
except OSError:
GError(_("Unable to set permission. Operation canceled."), parent=self)
return
return None

# check GRASS_ADDON_PATH
addonPath = os.getenv("GRASS_ADDON_PATH", [])
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/mapwin/buffered.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def Draw(
pdc.EndDrawing()

self.Refresh()
return
return None

if pdctype == "image": # draw selected image
bitmap = BitmapFromImage(img)
Expand Down Expand Up @@ -421,7 +421,7 @@ def Draw(
pdc.SetBrush(wx.Brush(wx.CYAN, wx.TRANSPARENT))
pdc.SetPen(pen)
if len(coords) < 2:
return
return None
if pdctype == "polyline":
i = 1
while i < len(coords):
Expand Down Expand Up @@ -497,7 +497,7 @@ def Draw(

elif pdctype == "text": # draw text on top of map
if not img["active"]:
return # only draw active text
return None # only draw active text
rotation = float(img["rotation"]) if "rotation" in img else 0.0
w, h = self.GetFullTextExtent(img["text"])[0:2]
pdc.SetFont(img["font"])
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/modules/colorrules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,7 @@ def _apply(self, updatePreview=True):
else:
if not self.properties["storeColumn"]:
GError(_("No color column defined. Operation canceled."), parent=self)
return
return None

self.UseAttrColumn(True)

Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/modules/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _getCmd(self):
item = self.tree.GetSelected()
if not item or "command" not in item[0].data:
GError(_("Extension not defined"), parent=self)
return
return None

name = item[0].data["command"]

Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/nviz/mapwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ def _loadRaster(self, item):
layer = self.tree.GetLayerInfo(item, key="maplayer")

if layer.type not in {"raster", "raster_3d"}:
return
return None

if layer.type == "raster":
id = self._display.LoadSurface(str(layer.name), None, None)
Expand Down Expand Up @@ -1826,7 +1826,7 @@ def LoadVector(self, item, points=None, append=True):
"""
layer = self.tree.GetLayerInfo(item, key="maplayer")
if layer.type != "vector":
return
return None

# set default properties
if points is None:
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/photo2image/ip2i_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ def GetNewExtent(self, region, map=None):

if not self.CheckGCPcount(msg=True):
self.gr_order = order
return
return None

self.gr_order = order

Expand Down Expand Up @@ -1410,7 +1410,7 @@ def GetNewExtent(self, region, map=None):
"Could not calculate new extends.\nPossible error with m.transform."
),
)
return
return None

# fist corner
e, n = errlist[0].split()
Expand Down Expand Up @@ -1751,7 +1751,7 @@ def AddGCPItem(self):
def DeleteGCPItem(self):
"""Deletes selected item in GCP list."""
if self.selected == wx.NOT_FOUND:
return
return None

key = self.GetItemData(self.selected)
self.DeleteItem(self.selected)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/psmap/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ def update(self):
mapInstr = self.instruction.FindInstructionByType("map")
if not mapInstr: # no map frame
GMessage(message=_("Please, create map frame first."))
return
return None

if self.rasterNoRadio.GetValue() or not self.rasterSelect.GetValue():
self.rasterDict["isRaster"] = False
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/psmap/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def Read(self, filename):
file = open(filename, encoding="Latin_1", errors="ignore")
except OSError:
GError(message=_("Unable to open file\n%s") % filename)
return
return None
# first read file to get information about region and scaletype
isRegionComment = False
orientation = "Portrait"
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/vdigit/toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ def StartEditing(self, mapLayer):
if dlg.ShowModal() == wx.ID_YES:
RunCommand("v.build", map=mapLayer.GetName())
else:
return
return None

# deactivate layer
self.Map.ChangeLayerActive(mapLayer, False)
Expand Down
Loading

0 comments on commit f533f55

Please sign in to comment.