diff --git a/gui/wxpython/core/utils.py b/gui/wxpython/core/utils.py index 66137f3c974..47977a1a27b 100644 --- a/gui/wxpython/core/utils.py +++ b/gui/wxpython/core/utils.py @@ -1179,8 +1179,7 @@ def unregisterPid(pid): def get_shell_pid(env=None): """Get shell PID from the GIS environment or None""" try: - shell_pid = int(grass.gisenv(env=env)["PID"]) - return shell_pid + return int(grass.gisenv(env=env)["PID"]) except (KeyError, ValueError) as error: Debug.msg( 1, "No PID for GRASS shell (assuming no shell running): {}".format(error) diff --git a/gui/wxpython/core/workspace.py b/gui/wxpython/core/workspace.py index 65a802d0809..7e5f85d6649 100644 --- a/gui/wxpython/core/workspace.py +++ b/gui/wxpython/core/workspace.py @@ -92,9 +92,7 @@ def __filterValue(self, value): :param value: """ value = value.replace("<", "<") - value = value.replace(">", ">") - - return value + return value.replace(">", ">") def __getNodeText(self, node, tag, default=""): """Get node text""" @@ -1043,9 +1041,7 @@ def __filterValue(self, value): """Make value XML-valid""" value = value.replace("<", "<") value = value.replace(">", ">") - value = value.replace("&", "&") - - return value + return value.replace("&", "&") def __writeLayer(self, mapTree, item): """Write bunch of layers to GRASS Workspace XML file""" diff --git a/gui/wxpython/datacatalog/tree.py b/gui/wxpython/datacatalog/tree.py index 085b9cb7f67..6d5530733d1 100644 --- a/gui/wxpython/datacatalog/tree.py +++ b/gui/wxpython/datacatalog/tree.py @@ -359,8 +359,7 @@ def _getValidSavedGrassDBs(self): dbs = UserSettings.Get( group="datacatalog", key="grassdbs", subkey="listAsString" ) - dbs = [db for db in dbs.split(",") if os.path.isdir(db)] - return dbs + return [db for db in dbs.split(",") if os.path.isdir(db)] def _saveGrassDBs(self): """Save current grass dbs in tree to settings""" diff --git a/gui/wxpython/gcp/manager.py b/gui/wxpython/gcp/manager.py index 87b18f8437d..692de174f55 100644 --- a/gui/wxpython/gcp/manager.py +++ b/gui/wxpython/gcp/manager.py @@ -1792,7 +1792,7 @@ def _getOverWriteDialog(self, maptype, overwrite): map_name = "<{}>".format(found["name"]) if found["name"] and not overwrite: - overwrite_dlg = wx.MessageDialog( + return wx.MessageDialog( self.GetParent(), message=_( "The {map_type} map {map_name} exists. " @@ -1804,7 +1804,6 @@ def _getOverWriteDialog(self, maptype, overwrite): caption=_("Overwrite?"), style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION, ) - return overwrite_dlg def OnGeorect(self, event): """ diff --git a/gui/wxpython/gmodeler/model.py b/gui/wxpython/gmodeler/model.py index 864f1df68e9..f0599b70d61 100644 --- a/gui/wxpython/gmodeler/model.py +++ b/gui/wxpython/gmodeler/model.py @@ -2027,9 +2027,7 @@ def _filterValue(self, value): :param value: """ value = value.replace("<", "<") - value = value.replace(">", ">") - - return value + return value.replace(">", ">") def _getNodeText(self, node, tag, default=""): """Get node text""" @@ -2342,8 +2340,7 @@ def _filterValue(self, value): :param value: string to be escaped as XML :return: a XML-valid string """ - value = saxutils.escape(value) - return value + return saxutils.escape(value) def _header(self): """Write header""" diff --git a/gui/wxpython/gui_core/dialogs.py b/gui/wxpython/gui_core/dialogs.py index 167a48ce6bb..9a19000e6e4 100644 --- a/gui/wxpython/gui_core/dialogs.py +++ b/gui/wxpython/gui_core/dialogs.py @@ -1208,8 +1208,7 @@ def _filter(self, data): """Apply filter for strings in data list""" flt_data = [] if len(self.flt_pattern) == 0: - flt_data = data[:] - return flt_data + return data[:] for dt in data: try: @@ -1872,8 +1871,7 @@ def __init__( def GetOpacity(self): """Button 'OK' pressed""" # return opacity value - opacity = float(self.value.GetValue()) / 100 - return opacity + return float(self.value.GetValue()) / 100 def OnApply(self, event): self.applyOpacity.emit(value=self.GetOpacity()) diff --git a/gui/wxpython/gui_core/forms.py b/gui/wxpython/gui_core/forms.py index 00fd505c799..1202d699eeb 100644 --- a/gui/wxpython/gui_core/forms.py +++ b/gui/wxpython/gui_core/forms.py @@ -3062,8 +3062,7 @@ def AddBitmapToImageList(self, section, imageList): image = wx.Image(iconSectionDict[section]).Scale( 16, 16, wx.IMAGE_QUALITY_HIGH ) - idx = imageList.Add(BitmapFromImage(image)) - return idx + return imageList.Add(BitmapFromImage(image)) return -1 diff --git a/gui/wxpython/gui_core/gselect.py b/gui/wxpython/gui_core/gselect.py index 6b679c074b5..dc553ae74bb 100644 --- a/gui/wxpython/gui_core/gselect.py +++ b/gui/wxpython/gui_core/gselect.py @@ -663,8 +663,7 @@ def AddItem(self, value, mapset=None, node=True, parent=None): data = {"node": node, "mapset": mapset} - item = self.seltree.AppendItem(parent, text=value, data=data) - return item + return self.seltree.AppendItem(parent, text=value, data=data) def OnKeyUp(self, event): """Enables to select items using keyboard diff --git a/gui/wxpython/gui_core/pyedit.py b/gui/wxpython/gui_core/pyedit.py index 7c56a7f7c07..573496cbbfc 100644 --- a/gui/wxpython/gui_core/pyedit.py +++ b/gui/wxpython/gui_core/pyedit.py @@ -301,8 +301,7 @@ def _openFile(self, file_path): """ try: with open(file_path, "r") as f: - content = f.read() - return content + return f.read() except PermissionError: GError( message=_( diff --git a/gui/wxpython/gui_core/simplelmgr.py b/gui/wxpython/gui_core/simplelmgr.py index d59a443c9b0..9f03a49396e 100644 --- a/gui/wxpython/gui_core/simplelmgr.py +++ b/gui/wxpython/gui_core/simplelmgr.py @@ -377,31 +377,27 @@ def GetOptData(self, dcmd, layer, params, propwin): def AddRaster(self, name, cmd, hidden, dialog): """Ads new raster layer.""" - layer = self._layerList.AddNewLayer( + return self._layerList.AddNewLayer( name=name, mapType="raster", active=True, cmd=cmd, hidden=hidden ) - return layer def AddRast3d(self, name, cmd, hidden, dialog): """Ads new raster3d layer.""" - layer = self._layerList.AddNewLayer( + return self._layerList.AddNewLayer( name=name, mapType="raster_3d", active=True, cmd=cmd, hidden=hidden ) - return layer def AddVector(self, name, cmd, hidden, dialog): """Ads new vector layer.""" - layer = self._layerList.AddNewLayer( + return self._layerList.AddNewLayer( name=name, mapType="vector", active=True, cmd=cmd, hidden=hidden ) - return layer def AddRGB(self, name, cmd, hidden, dialog): """Ads new vector layer.""" - layer = self._layerList.AddNewLayer( + return self._layerList.AddNewLayer( name=name, mapType="rgb", active=True, cmd=cmd, hidden=hidden ) - return layer def GetLayerInfo(self, layer, key): """Just for compatibility, should be removed in the future""" diff --git a/gui/wxpython/gui_core/treeview.py b/gui/wxpython/gui_core/treeview.py index 01bbe87d493..4c20885599c 100644 --- a/gui/wxpython/gui_core/treeview.py +++ b/gui/wxpython/gui_core/treeview.py @@ -91,8 +91,7 @@ def OnGetItemText(self, index, column=0): """ node = self._model.GetNodeByIndex(index) # remove & because of & needed in menu (&Files) - label = node.label.replace("&", "") - return label + return node.label.replace("&", "") def OnGetChildrenCount(self, index): """Overridden method necessary to communicate with tree model.""" @@ -258,8 +257,7 @@ def OnGetItemText(self, index, column=0): if column > 0: return node.data.get(self._columns[column], "") else: - label = node.label.replace("&", "") - return label + return node.label.replace("&", "") def OnRightClick(self, event): """Select item on right click. diff --git a/gui/wxpython/gui_core/widgets.py b/gui/wxpython/gui_core/widgets.py index 61225b8c21f..3196ff173db 100644 --- a/gui/wxpython/gui_core/widgets.py +++ b/gui/wxpython/gui_core/widgets.py @@ -1338,11 +1338,7 @@ def _searchModule(self, keys, value): nodes.sort(key=self._model.GetIndexOfNode) self._results = nodes self._resultIndex = -1 - commands = sorted( - [node.data["command"] for node in nodes if node.data["command"]] - ) - - return commands + return sorted([node.data["command"] for node in nodes if node.data["command"]]) def OnSelectModule(self, event=None): """Module selected from choice, update command prompt""" diff --git a/gui/wxpython/history/tree.py b/gui/wxpython/history/tree.py index 0e9d75870aa..8bccc3e97a7 100644 --- a/gui/wxpython/history/tree.py +++ b/gui/wxpython/history/tree.py @@ -215,12 +215,10 @@ def _timestampToDay(self, timestamp=None): return OLD_DATE timestamp_datetime = datetime.datetime.fromisoformat(timestamp) - day_midnight = datetime.datetime( + return datetime.datetime( timestamp_datetime.year, timestamp_datetime.month, timestamp_datetime.day ).date() - return day_midnight - def _initHistoryModel(self): """Fill tree history model based on the current history log.""" content_list = self.ReadFromHistory() diff --git a/gui/wxpython/iclass/digit.py b/gui/wxpython/iclass/digit.py index 691c1e75080..a6f0ef15948 100644 --- a/gui/wxpython/iclass/digit.py +++ b/gui/wxpython/iclass/digit.py @@ -126,8 +126,7 @@ def _getNewFeaturesLayer(self): return 1 def _getNewFeaturesCat(self): - cat = self.mapWindow.GetCurrentCategory() - return cat + return self.mapWindow.GetCurrentCategory() def DeleteAreasByCat(self, cats): """Delete areas (centroid+boundaries) by categories diff --git a/gui/wxpython/iscatt/frame.py b/gui/wxpython/iscatt/frame.py index bf5dfac91e4..6d87a90e273 100644 --- a/gui/wxpython/iscatt/frame.py +++ b/gui/wxpython/iscatt/frame.py @@ -330,8 +330,7 @@ def _newScatterPlotName(self, scatt_id): return name def _getScatterPlotName(self, i): - name = "scatter plot %d" % i - return name + return "scatter plot %d" % i def NewScatterPlot(self, scatt_id, transpose): # TODO needs to be resolved (should be in this class) diff --git a/gui/wxpython/iscatt/iscatt_core.py b/gui/wxpython/iscatt/iscatt_core.py index c663233a5e8..2eaa463940d 100644 --- a/gui/wxpython/iscatt/iscatt_core.py +++ b/gui/wxpython/iscatt/iscatt_core.py @@ -488,9 +488,7 @@ def GetBandsInfo(self, scatt_id): b1_info = self.an_data.GetBandInfo(b1) b2_info = self.an_data.GetBandInfo(b2) - bands_info = {"b1": b1_info, "b2": b2_info} - - return bands_info + return {"b1": b1_info, "b2": b2_info} def DeleScattPlot(self, cat_id, scatt_id): if cat_id not in self.cats: @@ -784,15 +782,13 @@ def idBandsToidScatt(band_1_id, band_2_id, n_bands): n_b1 = n_bands - 1 - scatt_id = int( + return int( (band_1_id * (2 * n_b1 + 1) - band_1_id * band_1_id) / 2 + band_2_id - band_1_id - 1 ) - return scatt_id - def GetRegion(): ret, region, msg = RunCommand("g.region", flags="gp", getErrorMsg=True, read=True) diff --git a/gui/wxpython/iscatt/plots.py b/gui/wxpython/iscatt/plots.py index ba951e0eec3..f9cad136314 100644 --- a/gui/wxpython/iscatt/plots.py +++ b/gui/wxpython/iscatt/plots.py @@ -711,8 +711,7 @@ def GetCoords(self): if self.empty_pol: return None - coords = deepcopy(self.pol.xy) - return coords + return deepcopy(self.pol.xy) def SetEmpty(self): self._setEmptyPol(True) diff --git a/gui/wxpython/lmgr/frame.py b/gui/wxpython/lmgr/frame.py index 0b5a07b8f07..ddb91789508 100644 --- a/gui/wxpython/lmgr/frame.py +++ b/gui/wxpython/lmgr/frame.py @@ -2336,13 +2336,12 @@ def MsgDisplayResolution(self, limitText=None): ) if limitText: message += "\n\n%s" % _(limitText) - dlg = wx.MessageDialog( + return wx.MessageDialog( parent=self, message=message, caption=_("Constrain map to region geometry?"), style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION | wx.CENTRE, ) - return dlg def _onMapsetWatchdog(self, map_path, map_dest): """Current mapset watchdog event handler diff --git a/gui/wxpython/lmgr/layertree.py b/gui/wxpython/lmgr/layertree.py index 3ef19ba46b1..e935af8ce5d 100644 --- a/gui/wxpython/lmgr/layertree.py +++ b/gui/wxpython/lmgr/layertree.py @@ -2428,7 +2428,7 @@ def _createCommandCtrl(self): height = 25 if sys.platform in {"win32", "darwin"}: height = 40 - ctrl = TextCtrl( + return TextCtrl( self, id=wx.ID_ANY, value="", @@ -2436,4 +2436,3 @@ def _createCommandCtrl(self): size=(self.GetSize()[0] - 100, height), style=wx.TE_PROCESS_ENTER | wx.TE_DONTWRAP, ) - return ctrl diff --git a/gui/wxpython/location_wizard/wizard.py b/gui/wxpython/location_wizard/wizard.py index 408371ad21c..41c84d4ca70 100644 --- a/gui/wxpython/location_wizard/wizard.py +++ b/gui/wxpython/location_wizard/wizard.py @@ -743,8 +743,7 @@ def GetSortImages(self): def OnGetItemText(self, item, col): """Get item text""" index = self.itemIndexMap[item] - s = str(self.itemDataMap[index][col]) - return s + return str(self.itemDataMap[index][col]) def OnGetItemImage(self, item): return -1 @@ -2795,9 +2794,7 @@ def CreateProj4String(self): for item in datumparams: proj4string = "%s +%s" % (proj4string, item) - proj4string = "%s +no_defs" % proj4string - - return proj4string + return "%s +no_defs" % proj4string def OnHelp(self, event): """'Help' button clicked""" diff --git a/gui/wxpython/main_window/frame.py b/gui/wxpython/main_window/frame.py index 57cf6efb868..6b9a9be640f 100644 --- a/gui/wxpython/main_window/frame.py +++ b/gui/wxpython/main_window/frame.py @@ -2430,13 +2430,12 @@ def MsgDisplayResolution(self, limitText=None): ) if limitText: message += "\n\n%s" % _(limitText) - dlg = wx.MessageDialog( + return wx.MessageDialog( parent=self, message=message, caption=_("Constrain map to region geometry?"), style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION | wx.CENTRE, ) - return dlg def _onMapsetWatchdog(self, map_path, map_dest): """Current mapset watchdog event handler diff --git a/gui/wxpython/nviz/mapwindow.py b/gui/wxpython/nviz/mapwindow.py index 3d282cc3c14..30a7682f6c7 100644 --- a/gui/wxpython/nviz/mapwindow.py +++ b/gui/wxpython/nviz/mapwindow.py @@ -243,7 +243,7 @@ def GetContentScaleFactor(self): def InitFly(self): """Initialize fly through dictionary""" - fly = { + return { "interval": 10, # interval for timerFly "value": [0, 0, 0], # calculated values for navigation "mode": 0, # fly through mode (0, 1) @@ -264,8 +264,6 @@ def InitFly(self): "flySpeedStep": 2, } - return fly - def OnTimerFly(self, event): """Fly event was emitted, move the scene""" if self.mouse["use"] != "fly": diff --git a/gui/wxpython/nviz/wxnviz.py b/gui/wxpython/nviz/wxnviz.py index f967d830d5d..8002d6f32d2 100644 --- a/gui/wxpython/nviz/wxnviz.py +++ b/gui/wxpython/nviz/wxnviz.py @@ -2212,9 +2212,7 @@ def Load(self): ] wx.EndBusyCursor() - id = Nviz_load_image(im, self.width, self.height, self.image.HasAlpha()) - - return id + return Nviz_load_image(im, self.width, self.height, self.image.HasAlpha()) def Draw(self): """Draw texture as an image""" diff --git a/gui/wxpython/psmap/dialogs.py b/gui/wxpython/psmap/dialogs.py index 6094c805e60..8ee3661d8b5 100644 --- a/gui/wxpython/psmap/dialogs.py +++ b/gui/wxpython/psmap/dialogs.py @@ -3200,8 +3200,7 @@ def getColsChoice(self, parent): else: cols = [] - choice = Choice(parent=parent, id=wx.ID_ANY, choices=cols) - return choice + return Choice(parent=parent, id=wx.ID_ANY, choices=cols) def update(self): # feature type diff --git a/gui/wxpython/psmap/frame.py b/gui/wxpython/psmap/frame.py index a03021acc2f..4f0a2220fd5 100644 --- a/gui/wxpython/psmap/frame.py +++ b/gui/wxpython/psmap/frame.py @@ -2613,9 +2613,7 @@ def ImageRect(self): iH = iH * self.currScale x = cW / 2 - iW / 2 y = cH / 2 - iH / 2 - imageRect = Rect(int(x), int(y), int(iW), int(iH)) - - return imageRect + return Rect(int(x), int(y), int(iW), int(iH)) def RedrawSelectBox(self, id): """Redraws select box when selected object changes its size""" diff --git a/gui/wxpython/psmap/instructions.py b/gui/wxpython/psmap/instructions.py index bca686898cb..bc10a1c0e46 100644 --- a/gui/wxpython/psmap/instructions.py +++ b/gui/wxpython/psmap/instructions.py @@ -1913,8 +1913,7 @@ def __init__(self, id, env): self.instruction = dict(self.defaultInstruction) def __str__(self): - instr = string.Template("raster $raster").substitute(self.instruction) - return instr + return string.Template("raster $raster").substitute(self.instruction) def Read(self, instruction, text): """Read instruction and save information""" diff --git a/gui/wxpython/psmap/utils.py b/gui/wxpython/psmap/utils.py index 3e60ad6c2b6..d54a45a52be 100644 --- a/gui/wxpython/psmap/utils.py +++ b/gui/wxpython/psmap/utils.py @@ -402,8 +402,7 @@ def getRasterType(map): map = "" file = gs.find_file(name=map, element="cell") if file.get("file"): - rasterType = gs.raster_info(map)["datatype"] - return rasterType + return gs.raster_info(map)["datatype"] else: return None diff --git a/gui/wxpython/rlisetup/sampling_frame.py b/gui/wxpython/rlisetup/sampling_frame.py index 2526d0537f8..dcd8398d049 100644 --- a/gui/wxpython/rlisetup/sampling_frame.py +++ b/gui/wxpython/rlisetup/sampling_frame.py @@ -385,8 +385,7 @@ def writeCircle(self, circle, rasterName): grass.use_temp_region() grass.run_command("g.region", zoom=rasterName) region = grass.region() - marea = MaskedArea(region, rasterName, circle.radius) - return marea + return MaskedArea(region, rasterName, circle.radius) def _rectangleDrawn(self): """When drawing finished, get region values""" diff --git a/gui/wxpython/startup/guiutils.py b/gui/wxpython/startup/guiutils.py index 8bf4debef66..d9f59696375 100644 --- a/gui/wxpython/startup/guiutils.py +++ b/gui/wxpython/startup/guiutils.py @@ -165,9 +165,8 @@ def create_location_interactively(guiparent, grassdb): gWizard = LocationWizard(parent=guiparent, grassdatabase=grassdb) if gWizard.location is None: - gWizard_output = (None, None, None) + return (None, None, None) # Returns Nones after Cancel - return gWizard_output if gWizard.georeffile: message = _("Do you want to import {} to the newly created project?").format( diff --git a/gui/wxpython/startup/locdownload.py b/gui/wxpython/startup/locdownload.py index 5a4eddbaf9d..4592103a0f9 100644 --- a/gui/wxpython/startup/locdownload.py +++ b/gui/wxpython/startup/locdownload.py @@ -121,8 +121,7 @@ def _get_heigth(self, string): n_lines = string.count("\n") attr = self.out.GetClassDefaultAttributes() font_size = attr.font.GetPointSize() - heigth = int((n_lines + 2) * font_size // 0.75) # 1 px = 0.75 pt - return heigth + return int((n_lines + 2) * font_size // 0.75) # 1 px = 0.75 pt def _resize(self, heigth=-1): """Resize widget heigth diff --git a/gui/wxpython/vnet/vnet_core.py b/gui/wxpython/vnet/vnet_core.py index deaf11ff670..17d85ef6ca4 100644 --- a/gui/wxpython/vnet/vnet_core.py +++ b/gui/wxpython/vnet/vnet_core.py @@ -1030,8 +1030,7 @@ def AddTmpMapAnalysisMsg(mapName, tmp_maps): # TODO "Temporary map %s already exists.\n" + "Do you want to continue in analysis and overwrite it?" ) % (mapName + "@" + grass.gisenv()["MAPSET"]) - tmpMap = tmp_maps.AddTmpVectMap(mapName, msg) - return tmpMap + return tmp_maps.AddTmpVectMap(mapName, msg) class SnappingNodes(wx.EvtHandler): diff --git a/gui/wxpython/vnet/vnet_data.py b/gui/wxpython/vnet/vnet_data.py index 9f2d11cf46a..e978a82314e 100644 --- a/gui/wxpython/vnet/vnet_data.py +++ b/gui/wxpython/vnet/vnet_data.py @@ -666,8 +666,7 @@ def _getInvalidParams(self, params): vectMaps = grass.list_grouped("vector")[mapSet] if not params["input"] or mapName not in vectMaps: - invParams = list(params.keys())[:] - return invParams + return list(params.keys())[:] # check arc/node layer layers = utils.GetVectorNumberOfLayers(params["input"]) @@ -1252,8 +1251,7 @@ def _parseValue(self, value, read=False): value[0] == "[" and value[-1] == "]" ): # TODO, possible wrong interpretation value = value[1:-1].split(",") - value = map(self._castValue, value) - return value + return map(self._castValue, value) if value == "True": value = True diff --git a/imagery/i.atcorr/create_iwave.py b/imagery/i.atcorr/create_iwave.py index b895d3d5125..243e7a22542 100644 --- a/imagery/i.atcorr/create_iwave.py +++ b/imagery/i.atcorr/create_iwave.py @@ -191,8 +191,7 @@ def pretty_print(filter_f): if i < len(filter_f): pstring += ", " # trim starting \n and trailing , - pstring = pstring.lstrip("\n").rstrip(", ") - return pstring + return pstring.lstrip("\n").rstrip(", ") def write_cpp(bands, values, sensor, folder): diff --git a/man/build_manual_gallery.py b/man/build_manual_gallery.py index 10fdb143989..414b36c8a85 100755 --- a/man/build_manual_gallery.py +++ b/man/build_manual_gallery.py @@ -123,8 +123,7 @@ def remove_module_name(string, module): string = string.replace(module.replace("wxGUI.", "g.gui."), "") string = string.replace(module.replace(".", "_"), "") # using _ string = string.replace(module.replace(".", ""), "") # using nothing - string = string.replace(module, "") # using original dots - return string + return string.replace(module, "") # using original dots def title_from_names(module_name, img_name): diff --git a/pyproject.toml b/pyproject.toml index ab792fe2ac6..2ca0e33f163 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -237,7 +237,13 @@ ignore = [ "PTH202", # os-path-getsize "PTH204", # os-path-getmtime "PTH207", # glob - "RET50", # flake8-return (RET) + "RET501", # unnecessary-return-none + "RET502", # implicit-return-value + "RET503", # implicit-return + "RET505", # superfluous-else-return + "RET506", # superfluous-else-raise + "RET507", # superfluous-else-continue + "RET508", # superfluous-else-break "RSE102", # unnecessary-paren-on-raise-exception "RUF002", # ambiguous-unicode-character-docstring "RUF003", # ambiguous-unicode-character-comment diff --git a/python/grass/grassdb/checks.py b/python/grass/grassdb/checks.py index c1ef7cc76c2..b8748de9876 100644 --- a/python/grass/grassdb/checks.py +++ b/python/grass/grassdb/checks.py @@ -605,9 +605,7 @@ def get_reasons_grassdb_not_removable(grassdb): locations = [] for g_location in g_locations: locations.append((grassdb, g_location)) - messages = get_reasons_locations_not_removable(locations) - - return messages + return get_reasons_locations_not_removable(locations) def get_list_of_locations(dbase): diff --git a/python/grass/grassdb/history.py b/python/grass/grassdb/history.py index ec7b1dc14eb..ba9ed818f36 100644 --- a/python/grass/grassdb/history.py +++ b/python/grass/grassdb/history.py @@ -53,8 +53,7 @@ def get_history_file_extension(history_path): :return str extension: None (plain text) or .json """ file_path = Path(history_path) - extension = file_path.suffix - return extension + return file_path.suffix def ensure_history_file(history_path): @@ -275,14 +274,13 @@ def get_initial_command_info(env_run): region_settings = gs.region(env=env_run) # Finalize the command info dictionary - cmd_info = { + return { "timestamp": exec_time, "mask2d": mask2d_present, "mask3d": mask3d_present, "region": region_settings, "status": Status.RUNNING.value, } - return cmd_info def _add_entry_to_JSON(history_path, entry): diff --git a/python/grass/gunittest/reporters.py b/python/grass/gunittest/reporters.py index e5455c33b39..63bffc655e1 100644 --- a/python/grass/gunittest/reporters.py +++ b/python/grass/gunittest/reporters.py @@ -295,7 +295,7 @@ def get_html_test_authors_table(directory, tests_authors): if not not_testing_authors: not_testing_authors = ["all recent authors contributed tests"] - test_authors = ( + return ( "
'
"Note that determination of authors is approximate and only"
@@ -311,7 +311,6 @@ def get_html_test_authors_table(directory, tests_authors):
not_testing=", ".join(sorted(not_testing_authors)),
)
)
- return test_authors
class GrassTestFilesMultiReporter:
@@ -1212,7 +1211,7 @@ def report_for_dir(self, root, directory, test_files):
page.close()
status = success_to_html_text(total=file_total, successes=file_successes)
- row = (
+ return (
""
' {d} {status} '
"{nfiles} {sfiles} {pfiles} "
@@ -1231,7 +1230,6 @@ def report_for_dir(self, root, directory, test_files):
ptests=dir_pass_per,
)
)
- return row
def report_for_dirs(self, root, directories):
# TODO: this will need changes according to potential changes in
diff --git a/python/grass/imaging/images2gif.py b/python/grass/imaging/images2gif.py
index b80f452cf8c..ba681dca77d 100644
--- a/python/grass/imaging/images2gif.py
+++ b/python/grass/imaging/images2gif.py
@@ -1105,8 +1105,7 @@ def convert(self, *color):
def inxsearch(self, r, g, b):
"""Search for BGR values 0..255 and return colour index"""
dists = self.colormap[:, :3] - np.array([r, g, b])
- a = np.argmin((dists * dists).sum(1))
- return a
+ return np.argmin((dists * dists).sum(1))
if __name__ == "__main__":
diff --git a/python/grass/jupyter/utils.py b/python/grass/jupyter/utils.py
index f06adfa36d1..4d76b166361 100644
--- a/python/grass/jupyter/utils.py
+++ b/python/grass/jupyter/utils.py
@@ -113,8 +113,7 @@ def estimate_resolution(raster, mapset, location, dbase, env):
output = gs.parse_key_val(output, val_type=float)
cell_ns = (output["n"] - output["s"]) / output["rows"]
cell_ew = (output["e"] - output["w"]) / output["cols"]
- estimate = (cell_ew + cell_ns) / 2.0
- return estimate
+ return (cell_ew + cell_ns) / 2.0
def setup_location(name, path, epsg, src_env):
diff --git a/python/grass/pydispatch/saferef.py b/python/grass/pydispatch/saferef.py
index 6a65f262714..43be1175b19 100644
--- a/python/grass/pydispatch/saferef.py
+++ b/python/grass/pydispatch/saferef.py
@@ -28,8 +28,7 @@ def safeRef(target, onDelete=None):
"""but no %s, don't know how """
"""to create reference""" % (target, im_self, im_func)
)
- reference = BoundMethodWeakref(target=target, onDelete=onDelete)
- return reference
+ return BoundMethodWeakref(target=target, onDelete=onDelete)
if onDelete is not None:
return weakref.ref(target, onDelete)
else:
diff --git a/python/grass/pygrass/modules/interface/env.py b/python/grass/pygrass/modules/interface/env.py
index 4fbef04dae3..ad6e4c4800e 100644
--- a/python/grass/pygrass/modules/interface/env.py
+++ b/python/grass/pygrass/modules/interface/env.py
@@ -14,13 +14,12 @@ def get_env():
if gisrc is None:
raise RuntimeError("You are not in a GRASS session, GISRC not found.")
with open(gisrc, mode="r") as grc:
- env = dict(
+ return dict(
[
(k.strip(), v.strip())
for k, v in [row.split(":", 1) for row in grc if row]
]
)
- return env
def get_debug_level():
diff --git a/python/grass/pygrass/shell/show.py b/python/grass/pygrass/shell/show.py
index 94b0807debe..20b721e726b 100644
--- a/python/grass/pygrass/shell/show.py
+++ b/python/grass/pygrass/shell/show.py
@@ -7,5 +7,4 @@
def raw_figure(figpath):
with open(figpath, mode="rb") as data:
- res = data.read()
- return res
+ return data.read()
diff --git a/python/grass/pygrass/vector/geometry.py b/python/grass/pygrass/vector/geometry.py
index 5b39d547bec..6ddbd70db7d 100644
--- a/python/grass/pygrass/vector/geometry.py
+++ b/python/grass/pygrass/vector/geometry.py
@@ -1380,8 +1380,7 @@ def _centroid(self, side, idonly=False):
if idonly:
return v_id
else:
- cntr = Centroid(v_id=v_id, c_mapinfo=self.c_mapinfo)
- return cntr
+ return Centroid(v_id=v_id, c_mapinfo=self.c_mapinfo)
def left_centroid(self, idonly=False):
"""Return left centroid
diff --git a/python/grass/script/core.py b/python/grass/script/core.py
index 5458ea1cb78..b22815bafb6 100644
--- a/python/grass/script/core.py
+++ b/python/grass/script/core.py
@@ -983,9 +983,7 @@ def tempname(length, lowercase=False):
if not lowercase:
chars += string.ascii_uppercase
random_part = "".join(random.choice(chars) for _ in range(length))
- randomname = "tmp_" + random_part
-
- return randomname
+ return "tmp_" + random_part
def _compare_projection(dic):
diff --git a/python/grass/script/task.py b/python/grass/script/task.py
index 3dfe8049841..9ab76eedcb8 100644
--- a/python/grass/script/task.py
+++ b/python/grass/script/task.py
@@ -429,8 +429,7 @@ def _get_node_text(self, node, tag, default=""):
"""Get node text"""
p = node.find(tag)
if p is not None:
- res = " ".join(p.text.split())
- return res
+ return " ".join(p.text.split())
return default
@@ -453,9 +452,7 @@ def convert_xml_to_utf8(xml_text):
# modify: change the encoding to "utf-8", for correct parsing
xml_text_utf8 = xml_text.decode(enc.decode("ascii")).encode("utf-8")
p = re.compile(b'encoding="' + enc + b'"', re.IGNORECASE)
- xml_text_utf8 = p.sub(b'encoding="utf-8"', xml_text_utf8)
-
- return xml_text_utf8
+ return p.sub(b'encoding="utf-8"', xml_text_utf8)
def get_interface_description(cmd):
@@ -508,13 +505,12 @@ def get_interface_description(cmd):
)
desc = convert_xml_to_utf8(cmdout)
- desc = desc.replace(
+ return desc.replace(
b"grass-interface.dtd",
os.path.join(os.getenv("GISBASE"), "gui", "xml", "grass-interface.dtd").encode(
"utf-8"
),
)
- return desc
def parse_interface(name, parser=processTask, blackList=None):
diff --git a/python/grass/script/utils.py b/python/grass/script/utils.py
index 0269ff15d2d..13d049412a4 100644
--- a/python/grass/script/utils.py
+++ b/python/grass/script/utils.py
@@ -91,8 +91,7 @@ def diff_files(filename_a, filename_b):
differ = difflib.Differ()
fh_a = open(filename_a, "r")
fh_b = open(filename_b, "r")
- result = list(differ.compare(fh_a.readlines(), fh_b.readlines()))
- return result
+ return list(differ.compare(fh_a.readlines(), fh_b.readlines()))
def try_remove(path):
diff --git a/python/grass/temporal/abstract_space_time_dataset.py b/python/grass/temporal/abstract_space_time_dataset.py
index 7f8209d8072..6376261cf72 100644
--- a/python/grass/temporal/abstract_space_time_dataset.py
+++ b/python/grass/temporal/abstract_space_time_dataset.py
@@ -98,10 +98,7 @@ def create_map_register_name(self):
uuid_rand = str(uuid.uuid4()).replace("-", "")
- table_name = (
- self.get_new_map_instance(None).get_type() + "_map_register_" + uuid_rand
- )
- return table_name
+ return self.get_new_map_instance(None).get_type() + "_map_register_" + uuid_rand
@abstractmethod
def get_new_map_instance(self, ident=None):
diff --git a/python/grass/temporal/mapcalc.py b/python/grass/temporal/mapcalc.py
index 1d098f33647..5f29cd32747 100644
--- a/python/grass/temporal/mapcalc.py
+++ b/python/grass/temporal/mapcalc.py
@@ -481,9 +481,7 @@ def _operator_parser(expr, first, current):
expr = _parse_start_time_operator(expr, is_time_absolute, first, current)
expr = _parse_end_time_operator(expr, is_time_absolute, first, current)
expr = _parse_start_operators(expr, is_time_absolute, current)
- expr = _parse_end_operators(expr, is_time_absolute, current)
-
- return expr
+ return _parse_end_operators(expr, is_time_absolute, current)
###############################################################################
diff --git a/python/grass/temporal/spatial_extent.py b/python/grass/temporal/spatial_extent.py
index b30aaa799af..3bf67b3d533 100644
--- a/python/grass/temporal/spatial_extent.py
+++ b/python/grass/temporal/spatial_extent.py
@@ -294,7 +294,7 @@ def intersect_2d(self, extent):
if S < eS:
nS = eS
- new = SpatialExtent(
+ return SpatialExtent(
north=nN,
south=nS,
east=nE,
@@ -303,7 +303,6 @@ def intersect_2d(self, extent):
bottom=0,
proj=self.get_projection(),
)
- return new
def intersect(self, extent):
"""Return the three dimensional intersection as spatial_extent
@@ -459,7 +458,7 @@ def disjoint_union_2d(self, extent):
if S > eS:
nS = eS
- new = SpatialExtent(
+ return SpatialExtent(
north=nN,
south=nS,
east=nE,
@@ -468,7 +467,6 @@ def disjoint_union_2d(self, extent):
bottom=0,
proj=self.get_projection(),
)
- return new
def union(self, extent):
"""Return the three dimensional union as spatial_extent
diff --git a/python/grass/temporal/temporal_algebra.py b/python/grass/temporal/temporal_algebra.py
index 66a24a3a154..fefb4e00f60 100644
--- a/python/grass/temporal/temporal_algebra.py
+++ b/python/grass/temporal/temporal_algebra.py
@@ -1179,8 +1179,7 @@ def set_temporal_extent_list(self, maplist, topolist=["EQUAL"], temporal="l"):
# resultlist.append(map_new)
# Get sorted map objects as values from result dictionary.
resultlist = resultdict.values()
- resultlist = sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
- return resultlist
+ return sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
def remove_maps(self):
"""Removes empty or intermediate maps of different type."""
@@ -1641,9 +1640,7 @@ def build_spatio_temporal_topology_list(
resultlist = resultdict.values()
# Sort list of maps chronological.
- resultlist = sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
-
- return resultlist
+ return sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
def assign_bool_value(
self, map_i, temporal_topo_list=["EQUAL"], spatial_topo_list=[]
@@ -1871,8 +1868,7 @@ def perform_temporal_selection(
# map_i.condition_value.append(False)
# Sort list of maps chronological.
- resultlist = sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
- return resultlist
+ return sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
def set_granularity(self, maplistA, maplistB, toperator="l", topolist=["EQUAL"]):
"""This function sets the temporal extends of a list of maps based on
@@ -2006,13 +2002,11 @@ def set_granularity(self, maplistA, maplistB, toperator="l", topolist=["EQUAL"])
resultlist = resultdict.values()
# Sort list of maps chronological.
- resultlist = sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
# Get relations to maplistB per map in A.
# Loop over all relations from list
# temporal extent = map.temporal_intersection(map)
# if temporal extend is None = delete map.
-
- return resultlist
+ return sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
def get_temporal_func_dict(self, map):
"""This function creates a dictionary containing temporal functions for a
@@ -2196,18 +2190,15 @@ def eval_map_list(self, maplist, thenlist, topolist=["EQUAL"]):
"""
# Get topology of then statement map list in relation to the other maplist
# and assign boolean values of the maplist to the thenlist.
- containlist = self.perform_temporal_selection(
- thenlist, maplist, assign_val=True, topolist=topolist
- )
# Inverse selection of maps from thenlist and assigning False values.
# excludelist = self.perform_temporal_selection(thenlist, maplist,
# assign_val = True,
# inverse = True,
# topolist = topolist)
# Combining the selection and inverse selection list.
- resultlist = containlist # + excludelist
-
- return resultlist
+ return self.perform_temporal_selection(
+ thenlist, maplist, assign_val=True, topolist=topolist
+ )
def build_condition_list(self, tvarexpr, thenlist, topolist=["EQUAL"]):
"""This function evaluates temporal variable expressions of a conditional
@@ -2285,9 +2276,7 @@ def build_condition_list(self, tvarexpr, thenlist, topolist=["EQUAL"]):
resultlist = self.eval_global_var(expr, thenlist)
# Sort resulting list of maps chronological.
- resultlist = sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
-
- return resultlist
+ return sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
def eval_condition_list(self, maplist, inverse=False):
"""This function evaluates conditional values of a map list.
@@ -2336,9 +2325,7 @@ def recurse_compare(conditionlist):
conditionlist[ele_index - 2] = result
recurse_compare(conditionlist)
- resultlist = conditionlist
-
- return resultlist
+ return conditionlist
resultlist = []
inverselist = []
diff --git a/python/grass/temporal/temporal_raster_base_algebra.py b/python/grass/temporal/temporal_raster_base_algebra.py
index f9333d79044..4ca921adaaf 100644
--- a/python/grass/temporal/temporal_raster_base_algebra.py
+++ b/python/grass/temporal/temporal_raster_base_algebra.py
@@ -354,9 +354,7 @@ def build_spatio_temporal_topology_list(
resultlist = resultdict.values()
# Sort list of maps chronological.
- resultlist = sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
-
- return resultlist
+ return sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
def build_command_string(self, map_i, relmap, operator=None, cmd_type=None):
"""This function build the r.mapcalc command string for conditionals,
@@ -636,9 +634,7 @@ def set_temporal_extent_list(
# resultlist.append(map_new)
# Get sorted map objects as values from result dictionary.
resultlist = resultdict.values()
- resultlist = sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
-
- return resultlist
+ return sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
def build_condition_cmd_list(
self,
@@ -739,14 +735,13 @@ def build_condition_cmd_list(
conditiontopolist = self.build_spatio_temporal_topology_list(
iflist, conclusionlist, topolist=condition_topolist
)
- resultlist = self.set_temporal_extent_list(
+ return self.set_temporal_extent_list(
conditiontopolist,
topolist=condition_topolist,
temporal="r",
cmd_bool=True,
cmd_type="condition",
)
- return resultlist
def p_statement_assign(self, t):
# This function executes the processing of raster/raster3d algebra
diff --git a/python/grass/temporal/temporal_vector_algebra.py b/python/grass/temporal/temporal_vector_algebra.py
index 7afc9978df6..d8e8474f26e 100644
--- a/python/grass/temporal/temporal_vector_algebra.py
+++ b/python/grass/temporal/temporal_vector_algebra.py
@@ -291,9 +291,7 @@ def build_spatio_temporal_topology_list(
resultlist = resultdict.values()
# Sort list of maps chronological.
- resultlist = sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
-
- return resultlist
+ return sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
def overlay_cmd_value(self, map_i, tbrelations, function, topolist=["EQUAL"]):
"""Function to evaluate two map lists by given overlay operator.
@@ -411,8 +409,7 @@ def set_temporal_extent_list(self, maplist, topolist=["EQUAL"], temporal="l"):
# resultlist.append(map_new)
# Get sorted map objects as values from result dictionary.
resultlist = resultdict.values()
- resultlist = sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
- return resultlist
+ return sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime)
def p_statement_assign(self, t):
# The expression should always return a list of maps.
diff --git a/scripts/r.semantic.label/testsuite/test_r_semantic_label.py b/scripts/r.semantic.label/testsuite/test_r_semantic_label.py
index 04be5d5b7bf..b7456e22633 100644
--- a/scripts/r.semantic.label/testsuite/test_r_semantic_label.py
+++ b/scripts/r.semantic.label/testsuite/test_r_semantic_label.py
@@ -24,9 +24,7 @@ def tearDownClass(cls):
def read_semantic_label(self):
with RasterRow(self.map) as rast:
- semantic_label = rast.info.semantic_label
-
- return semantic_label
+ return rast.info.semantic_label
def test_semantic_label_assign_not_current_mapset(self):
if not self.mapset == "PERMANENT":
diff --git a/scripts/v.import/v.import.py b/scripts/v.import/v.import.py
index 9dfe7b2149a..42e5952c76f 100755
--- a/scripts/v.import/v.import.py
+++ b/scripts/v.import/v.import.py
@@ -125,8 +125,7 @@ def cleanup():
def gdal_version():
"""Returns the GDAL version as tuple"""
- version = gs.parse_command("g.version", flags="reg")["gdal"]
- return version
+ return gs.parse_command("g.version", flags="reg")["gdal"]
def GDAL_COMPUTE_VERSION(maj, min, rev):
diff --git a/utils/md_isvalid.py b/utils/md_isvalid.py
index d7b2fbe6296..8b963bb953b 100644
--- a/utils/md_isvalid.py
+++ b/utils/md_isvalid.py
@@ -40,9 +40,7 @@ def check_module(module):
)
p.wait()
- returncode = p.returncode
-
- return returncode
+ return p.returncode
if __name__ == "__main__":
diff --git a/utils/mkhtml.py b/utils/mkhtml.py
index 69a1ba1db76..c5a7519872d 100644
--- a/utils/mkhtml.py
+++ b/utils/mkhtml.py
@@ -514,8 +514,7 @@ def get_last_git_commit(src_dir, addon_path, is_addon):
def read_file(name):
try:
with open(name) as f:
- s = f.read()
- return s
+ return f.read()
except OSError:
return ""
diff --git a/utils/test_generate_last_commit_file.py b/utils/test_generate_last_commit_file.py
index 3183b786c78..e6218b9cc4f 100644
--- a/utils/test_generate_last_commit_file.py
+++ b/utils/test_generate_last_commit_file.py
@@ -28,8 +28,7 @@
@pytest.fixture
def json_file():
- file_name = "core_modules_with_last_commit.json"
- return file_name
+ return "core_modules_with_last_commit.json"
@pytest.fixture