diff --git a/gui/wxpython/animation/nviztask.py b/gui/wxpython/animation/nviztask.py
index 92a6e767ce..437bba7946 100644
--- a/gui/wxpython/animation/nviztask.py
+++ b/gui/wxpython/animation/nviztask.py
@@ -285,11 +285,8 @@ class NvizTask:
toJoin = filter(self._ignore, toJoin)
return delim.join(map(str, toJoin))
- def _ignore(self, value):
- if value == "" or value is None:
- return False
- else:
- return True
+ def _ignore(self, value) -> bool:
+ return not (value == "" or value is None)
def ListMapParameters(self):
# params = self.task.get_list_params()
diff --git a/gui/wxpython/core/globalvar.py b/gui/wxpython/core/globalvar.py
index 60fdf7077b..7624183796 100644
--- a/gui/wxpython/core/globalvar.py
+++ b/gui/wxpython/core/globalvar.py
@@ -71,23 +71,18 @@ def version_as_string(version):
return ".".join(texts)
-def CheckWxPhoenix():
- if "phoenix" in wx.version():
- return True
- return False
+def CheckWxPhoenix() -> bool:
+ return "phoenix" in wx.version()
-def CheckWxVersion(version):
+def CheckWxVersion(version) -> bool:
"""Check wx version.
:return: True if current wx version is greater or equal than
- specifed version otherwise False
+ specified version otherwise False
"""
parsed_version = parse_version_string(wx.__version__)
- if parsed_version < version:
- return False
-
- return True
+ return not parsed_version < version
def CheckForWx():
diff --git a/gui/wxpython/core/render.py b/gui/wxpython/core/render.py
index 6e74ade9dc..021f3aa650 100644
--- a/gui/wxpython/core/render.py
+++ b/gui/wxpython/core/render.py
@@ -284,11 +284,9 @@ class Layer:
"""Check if layer is hidden"""
return self.hidden
- def IsRendered(self):
+ def IsRendered(self) -> bool:
"""!Check if layer was rendered (if the image file exists)"""
- if os.path.exists(self.mapfile):
- return True
- return False
+ return bool(os.path.exists(self.mapfile))
def SetType(self, ltype):
"""Set layer type"""
diff --git a/gui/wxpython/core/treemodel.py b/gui/wxpython/core/treemodel.py
index 3bcbd6c6ae..dd84fed7bf 100644
--- a/gui/wxpython/core/treemodel.py
+++ b/gui/wxpython/core/treemodel.py
@@ -229,15 +229,13 @@ class DictNode:
for child in self.children:
child.nprint(text, indent + 2)
- def match(self, key, value):
+ def match(self, key, value) -> bool:
"""Method used for searching according to given parameters.
:param value: dictionary value to be matched
:param key: data dictionary key
"""
- if key in self.data and self.data[key] == value:
- return True
- return False
+ return bool(key in self.data and self.data[key] == value)
class DictFilterNode(DictNode):
@@ -269,7 +267,7 @@ class DictFilterNode(DictNode):
return False
return True
- def _match_filtering(self, **kwargs):
+ def _match_filtering(self, **kwargs) -> bool:
"""Match method for filtering."""
if (
"type" in kwargs
@@ -277,13 +275,11 @@ class DictFilterNode(DictNode):
and kwargs["type"] != self.data["type"]
):
return False
- if (
+ return not (
"name" in kwargs
and "name" in self.data
and not kwargs["name"].search(self.data["name"])
- ):
- return False
- return True
+ )
class ModuleNode(DictNode):
diff --git a/gui/wxpython/core/utils.py b/gui/wxpython/core/utils.py
index 5e52fc0532..68242f0498 100644
--- a/gui/wxpython/core/utils.py
+++ b/gui/wxpython/core/utils.py
@@ -1077,7 +1077,7 @@ def autoCropImageFromFile(filename):
return wx.Image(filename)
-def isInRegion(regionA, regionB):
+def isInRegion(regionA, regionB) -> bool:
"""Tests if 'regionA' is inside of 'regionB'.
For example, region A is a display region and region B is some reference
@@ -1097,15 +1097,12 @@ def isInRegion(regionA, regionB):
:return: True if region A is inside of region B
:return: False otherwise
"""
- if (
+ return bool(
regionA["s"] >= regionB["s"]
and regionA["n"] <= regionB["n"]
and regionA["w"] >= regionB["w"]
and regionA["e"] <= regionB["e"]
- ):
- return True
-
- return False
+ )
def do_doctest_gettext_workaround():
@@ -1187,11 +1184,9 @@ def get_shell_pid(env=None):
return None
-def is_shell_running():
+def is_shell_running() -> bool:
"""Return True if a separate shell is registered in the GIS environment"""
- if get_shell_pid() is None:
- return False
- return True
+ return get_shell_pid() is not None
def parse_mapcalc_cmd(command):
diff --git a/gui/wxpython/dbmgr/base.py b/gui/wxpython/dbmgr/base.py
index 5aa5011ce9..2a58ce13e8 100644
--- a/gui/wxpython/dbmgr/base.py
+++ b/gui/wxpython/dbmgr/base.py
@@ -716,12 +716,9 @@ class VirtualAttributeList(
def OnGetItemImage(self, item):
return -1
- def IsEmpty(self):
+ def IsEmpty(self) -> bool:
"""Check if list if empty"""
- if self.columns:
- return False
-
- return True
+ return not self.columns
def _updateColSortFlag(self):
"""
diff --git a/gui/wxpython/gmodeler/model.py b/gui/wxpython/gmodeler/model.py
index 72e1e0419d..4596e0b04e 100644
--- a/gui/wxpython/gmodeler/model.py
+++ b/gui/wxpython/gmodeler/model.py
@@ -475,12 +475,9 @@ class Model:
# item.SetId(i)
# i += 1
- def IsValid(self):
+ def IsValid(self) -> bool:
"""Return True if model is valid"""
- if self.Validate():
- return False
-
- return True
+ return not self.Validate()
def Validate(self):
"""Validate model, return None if model is valid otherwise
@@ -820,12 +817,9 @@ class Model:
for item in self.items:
item.Update()
- def IsParameterized(self):
+ def IsParameterized(self) -> bool:
"""Return True if model is parameterized"""
- if self.Parameterize():
- return True
-
- return False
+ return bool(self.Parameterize())
def Parameterize(self):
"""Return parameterized options"""
@@ -3785,9 +3779,6 @@ class ModelParamDialog(wx.Dialog):
return errList
- def DeleteIntermediateData(self):
+ def DeleteIntermediateData(self) -> bool:
"""Check if to detele intermediate data"""
- if self.interData.IsShown() and self.interData.IsChecked():
- return True
-
- return False
+ return bool(self.interData.IsShown() and self.interData.IsChecked())
diff --git a/gui/wxpython/gui_core/vselect.py b/gui/wxpython/gui_core/vselect.py
index cefcc59662..0ff30afaaf 100644
--- a/gui/wxpython/gui_core/vselect.py
+++ b/gui/wxpython/gui_core/vselect.py
@@ -208,7 +208,7 @@ class VectorSelectBase:
if self._dialog:
self._dialog.Raise()
- def AddVecInfo(self, vInfoDictTMP):
+ def AddVecInfo(self, vInfoDictTMP) -> bool:
"""Update vector in list
Note: click on features add category
@@ -232,10 +232,7 @@ class VectorSelectBase:
if self._dialog:
self.slist.AddItem(vInfoDictTMP)
- if len(self.selectedFeatures) == 0:
- return False
-
- return True
+ return not len(self.selectedFeatures) == 0
def _draw(self):
"""Call class 'VectorSelectHighlighter' to draw selected features"""
diff --git a/gui/wxpython/iclass/frame.py b/gui/wxpython/iclass/frame.py
index 3aede6480c..c6a401ad4d 100644
--- a/gui/wxpython/iclass/frame.py
+++ b/gui/wxpython/iclass/frame.py
@@ -263,7 +263,7 @@ class IClassMapPanel(DoubleMapPanel):
return vectorName
- def RemoveTempVector(self):
+ def RemoveTempVector(self) -> bool:
"""Removes temporary vector map with training areas"""
ret = RunCommand(
prog="g.remove",
@@ -272,20 +272,16 @@ class IClassMapPanel(DoubleMapPanel):
type="vector",
name=self.trainingAreaVector,
)
- if ret != 0:
- return False
- return True
+ return bool(ret == 0)
- def RemoveTempRaster(self, raster):
+ def RemoveTempRaster(self, raster) -> bool:
"""Removes temporary raster maps"""
self.GetFirstMap().Clean()
self.GetSecondMap().Clean()
ret = RunCommand(
prog="g.remove", parent=self, flags="f", type="raster", name=raster
)
- if ret != 0:
- return False
- return True
+ return bool(ret == 0)
def AddToolbar(self, name):
"""Add defined toolbar to the window
@@ -817,7 +813,7 @@ class IClassMapPanel(DoubleMapPanel):
parent=self,
)
- def ExportAreas(self, vectorName, withTable):
+ def ExportAreas(self, vectorName, withTable) -> bool:
"""Export training areas to new vector map (with attribute table).
:param str vectorName: name of exported vector map
@@ -930,9 +926,7 @@ class IClassMapPanel(DoubleMapPanel):
)
wx.EndBusyCursor()
os.remove(dbFile.name)
- if ret != 0:
- return False
- return True
+ return bool(ret == 0)
def _runDBUpdate(self, tmpFile, table, column, value, cat):
"""Helper function for UPDATE statement
diff --git a/gui/wxpython/iscatt/plots.py b/gui/wxpython/iscatt/plots.py
index f9cad13631..08afe5906e 100644
--- a/gui/wxpython/iscatt/plots.py
+++ b/gui/wxpython/iscatt/plots.py
@@ -565,7 +565,7 @@ def _rendDtFilesToMemmaps(rend_dt):
del rend_dt[k]["sh"]
-def _renderCat(cat_id, rend_dt, scatt, styles):
+def _renderCat(cat_id, rend_dt, scatt, styles) -> bool:
return True
if cat_id not in rend_dt:
@@ -574,10 +574,7 @@ def _renderCat(cat_id, rend_dt, scatt, styles):
return False
if scatt["render"]:
return True
- if cat_id != 0 and rend_dt[cat_id]["color"] != styles[cat_id]["color"]:
- return True
-
- return False
+ return bool(cat_id != 0 and rend_dt[cat_id]["color"] != styles[cat_id]["color"])
def _getColorMap(cat_id, styles):
diff --git a/gui/wxpython/location_wizard/wizard.py b/gui/wxpython/location_wizard/wizard.py
index bdd955a7d3..5a206fafa5 100644
--- a/gui/wxpython/location_wizard/wizard.py
+++ b/gui/wxpython/location_wizard/wizard.py
@@ -293,11 +293,9 @@ class DatabasePage(TitledPage):
).format(ctrl.GetValue(), "/\"'@,=*~")
GError(parent=self, message=message, caption=_("Invalid name"))
- def _checkLocationNotExists(self, text):
+ def _checkLocationNotExists(self, text) -> bool:
"""Check whether user's input location exists or not."""
- if location_exists(self.tgisdbase.GetLabel(), text):
- return False
- return True
+ return not location_exists(self.tgisdbase.GetLabel(), text)
def _locationAlreadyExists(self, ctrl):
message = _(
diff --git a/gui/wxpython/mapdisp/gprint.py b/gui/wxpython/mapdisp/gprint.py
index c951475c13..b72a265f03 100644
--- a/gui/wxpython/mapdisp/gprint.py
+++ b/gui/wxpython/mapdisp/gprint.py
@@ -41,11 +41,8 @@ class MapPrint(wx.Printout):
def OnPreparePrinting(self):
super().OnPreparePrinting()
- def HasPage(self, page):
- if page <= 2:
- return True
- else:
- return False
+ def HasPage(self, page) -> bool:
+ return page <= 2
def GetPageInfo(self):
return (1, 2, 1, 2)
diff --git a/gui/wxpython/mapdisp/statusbar.py b/gui/wxpython/mapdisp/statusbar.py
index 0c5bac1012..72e9d0afdb 100644
--- a/gui/wxpython/mapdisp/statusbar.py
+++ b/gui/wxpython/mapdisp/statusbar.py
@@ -107,16 +107,14 @@ class SbManager:
"""
return self.statusbarItems[name].GetValue()
- def HasProperty(self, name):
+ def HasProperty(self, name) -> bool:
"""Checks whether property is represented by one of contained SbItems
:param name: name of SbItem (from name attribute)
:return: True if particular SbItem is contained, False otherwise
"""
- if name in self.statusbarItems:
- return True
- return False
+ return name in self.statusbarItems
def AddStatusbarItem(self, item):
"""Adds item to statusbar"""
diff --git a/gui/wxpython/mapswipe/dialogs.py b/gui/wxpython/mapswipe/dialogs.py
index ad846fd322..945aee590e 100644
--- a/gui/wxpython/mapswipe/dialogs.py
+++ b/gui/wxpython/mapswipe/dialogs.py
@@ -244,10 +244,8 @@ class SwipeMapDialog(wx.Dialog):
else:
return (self._firstLayerList, self._secondLayerList)
- def IsSimpleMode(self):
- if self._switchSizer.IsShown(self._firstPanel):
- return True
- return False
+ def IsSimpleMode(self) -> bool:
+ return bool(self._switchSizer.IsShown(self._firstPanel))
def GetFirstSimpleLmgr(self):
return self._firstLmgr
diff --git a/gui/wxpython/mapwin/decorations.py b/gui/wxpython/mapwin/decorations.py
index fef0258171..7ab010a1d3 100644
--- a/gui/wxpython/mapwin/decorations.py
+++ b/gui/wxpython/mapwin/decorations.py
@@ -126,10 +126,10 @@ class OverlayController:
dialog = property(fget=GetDialog, fset=SetDialog)
- def IsShown(self):
- if self._overlay and self._overlay.IsActive() and self._overlay.IsRendered():
- return True
- return False
+ def IsShown(self) -> bool:
+ return bool(
+ self._overlay and self._overlay.IsActive() and self._overlay.IsRendered()
+ )
def Show(self, show=True):
"""Activate or deactivate overlay."""
@@ -168,7 +168,7 @@ class OverlayController:
def _update(self):
self._renderer.ChangeOverlay(id=self._id, command=self._cmd)
- def CmdIsValid(self):
+ def CmdIsValid(self) -> bool:
"""If command is valid"""
return True
@@ -205,7 +205,7 @@ class DtextController(OverlayController):
self._defaultAt = "at=50,50"
self._cmd = ["d.text", self._defaultAt]
- def CmdIsValid(self):
+ def CmdIsValid(self) -> bool:
inputs = 0
for param in self._cmd[1:]:
param = param.split("=")
@@ -213,9 +213,7 @@ class DtextController(OverlayController):
inputs += 1
elif param[0] == "text" and len(param) == 2:
inputs += 1
- if inputs >= 1:
- return True
- return False
+ return inputs >= 1
class BarscaleController(OverlayController):
@@ -311,7 +309,7 @@ class LegendController(OverlayController):
return x, y
- def CmdIsValid(self):
+ def CmdIsValid(self) -> bool:
inputs = 0
for param in self._cmd[1:]:
param = param.split("=")
@@ -321,9 +319,7 @@ class LegendController(OverlayController):
inputs += 1
elif param[0] == "raster_3d" and len(param) == 2:
inputs += 1
- if inputs == 1:
- return True
- return False
+ return inputs == 1
def ResizeLegend(self, begin, end, screenSize):
"""Resize legend according to given bbox coordinates."""
diff --git a/gui/wxpython/modules/colorrules.py b/gui/wxpython/modules/colorrules.py
index 569bb4e5d7..0772dc7f9d 100644
--- a/gui/wxpython/modules/colorrules.py
+++ b/gui/wxpython/modules/colorrules.py
@@ -772,7 +772,7 @@ class ColorTable(wx.Frame):
self.ReadColorTable(ctable=ctable)
- def CreateColorTable(self, tmp=False):
+ def CreateColorTable(self, tmp=False) -> bool:
"""Creates color table
:return: True on success
@@ -822,10 +822,7 @@ class ColorTable(wx.Frame):
cmd = cmdlist_to_tuple(cmd)
ret = RunCommand(cmd[0], **cmd[1])
- if ret != 0:
- return False
-
- return True
+ return bool(ret == 0)
def DoPreview(self, ltype, cmdlist):
"""Update preview (based on computational region)"""
@@ -1241,15 +1238,12 @@ class VectorColorTable(ColorTable):
else:
self.cp.SetLabel(_("Import or export color table"))
- def CheckMapset(self):
+ def CheckMapset(self) -> bool:
"""Check if current vector is in current mapset"""
- if (
+ return bool(
gs.find_file(name=self.inmap, element="vector")["mapset"]
== gs.gisenv()["MAPSET"]
- ):
- return True
- else:
- return False
+ )
def NoConnection(self, vectorName):
dlg = wx.MessageDialog(
diff --git a/gui/wxpython/psmap/dialogs.py b/gui/wxpython/psmap/dialogs.py
index 42a3ef862e..740678de3c 100644
--- a/gui/wxpython/psmap/dialogs.py
+++ b/gui/wxpython/psmap/dialogs.py
@@ -2085,11 +2085,9 @@ class RasterDialog(PsmapDialog):
self.id = self.rPanel.getId()
self._layout(self.rPanel)
- def update(self):
+ def update(self) -> bool:
ok = self.rPanel.update()
- if ok:
- return True
- return False
+ return bool(ok)
def OnApply(self, event):
ok = self.update()
@@ -4410,12 +4408,10 @@ class LegendDialog(PsmapDialog):
self.parent.objectId.append(self.id[1])
return True
- def update(self):
+ def update(self) -> bool:
okR = self.updateRasterLegend()
okV = self.updateVectorLegend()
- if okR and okV:
- return True
- return False
+ return bool(okR and okV)
def updateDialog(self):
"""Update legend coordinates after moving"""
diff --git a/gui/wxpython/rlisetup/functions.py b/gui/wxpython/rlisetup/functions.py
index 2b9433ea4d..28f186fa39 100644
--- a/gui/wxpython/rlisetup/functions.py
+++ b/gui/wxpython/rlisetup/functions.py
@@ -65,15 +65,12 @@ def retRLiPath():
return rlipath
-def checkMapExists(name, typ="raster"):
+def checkMapExists(name, typ="raster") -> bool:
"""Check if a map already exist in the working mapset"""
env = grass.gisenv()
mapset = env["MAPSET"]
mapp = grass.find_file(name, typ, mapset)
- if mapp.name != "":
- return True
- else:
- return False
+ return bool(mapp.name != "")
def convertFeature(vect, outrast, cat, origrast, layer="1", overwrite=False):
diff --git a/gui/wxpython/timeline/frame.py b/gui/wxpython/timeline/frame.py
index 0330adbde3..bba9b7a371 100644
--- a/gui/wxpython/timeline/frame.py
+++ b/gui/wxpython/timeline/frame.py
@@ -57,7 +57,7 @@ ALPHA = 1
COLORS = ["b", "g", "r", "c", "m", "y", "k"]
-def check_version(*version):
+def check_version(*version) -> bool:
"""Checks if given version or newer is installed"""
versionInstalled = []
for i in mpl.__version__.split("."):
@@ -66,10 +66,7 @@ def check_version(*version):
versionInstalled.append(v)
except ValueError:
versionInstalled.append(0)
- if versionInstalled < list(version):
- return False
- else:
- return True
+ return versionInstalled >= list(version)
class TimelineFrame(wx.Frame):
diff --git a/gui/wxpython/tplot/frame.py b/gui/wxpython/tplot/frame.py
index 2f738c9364..8502808115 100755
--- a/gui/wxpython/tplot/frame.py
+++ b/gui/wxpython/tplot/frame.py
@@ -74,7 +74,7 @@ COLORS = ["b", "g", "r", "c", "m", "y", "k"]
LINEAR_REG_LINE_COLOR = (0.56, 0.00, 1.00)
-def check_version(*version):
+def check_version(*version) -> bool:
"""Checks if given version or newer is installed"""
versionInstalled = []
for i in mpl.__version__.split("."):
@@ -83,10 +83,7 @@ def check_version(*version):
versionInstalled.append(v)
except ValueError:
versionInstalled.append(0)
- if versionInstalled < list(version):
- return False
- else:
- return True
+ return not versionInstalled < list(version)
def findBetween(s, first, last):
diff --git a/gui/wxpython/vdigit/wxdisplay.py b/gui/wxpython/vdigit/wxdisplay.py
index a318105bd9..b747f3fa44 100644
--- a/gui/wxpython/vdigit/wxdisplay.py
+++ b/gui/wxpython/vdigit/wxdisplay.py
@@ -456,7 +456,7 @@ class DisplayDriver:
return ret
- def _isSelected(self, line, force=False):
+ def _isSelected(self, line, force=False) -> bool:
"""Check if vector object selected?
:param line: feature id
@@ -464,10 +464,7 @@ class DisplayDriver:
:return: True if vector object is selected
:return: False if vector object is not selected
"""
- if line in self.selected["ids"]:
- return True
-
- return False
+ return line in self.selected["ids"]
def _isDuplicated(self, line):
"""Check for already marked duplicates
@@ -556,7 +553,7 @@ class DisplayDriver:
return ftype
- def _validLine(self, line):
+ def _validLine(self, line) -> bool:
"""Check if feature id is valid
:param line: feature id
@@ -564,10 +561,7 @@ class DisplayDriver:
:return: True valid feature id
:return: False invalid
"""
- if line > 0 and line <= Vect_get_num_lines(self.poMapInfo):
- return True
-
- return False
+ return bool(line > 0 and line <= Vect_get_num_lines(self.poMapInfo))
def SelectLinesByBox(self, bbox, ltype=None, drawSeg=False, poMapInfo=None):
"""Select vector objects by given bounding box
diff --git a/gui/wxpython/vnet/vnet_data.py b/gui/wxpython/vnet/vnet_data.py
index e86931ca29..a1332398a1 100644
--- a/gui/wxpython/vnet/vnet_data.py
+++ b/gui/wxpython/vnet/vnet_data.py
@@ -1464,13 +1464,11 @@ class VNETGlobalTurnsData:
remove_to_angle = self.turn_data[row][2]
self.turn_data[prev_row][2] = remove_to_angle
- def IsInInterval(self, from_angle, to_angle, angle):
+ def IsInInterval(self, from_angle, to_angle, angle) -> bool:
"""Test if a direction includes or not includes a value"""
if to_angle < from_angle:
to_angle = math.pi * 2 + to_angle
if angle < from_angle:
angle = math.pi * 2 + angle
- if angle > from_angle and angle < to_angle:
- return True
- return False
+ return bool(angle > from_angle and angle < to_angle)
diff --git a/gui/wxpython/vnet/widgets.py b/gui/wxpython/vnet/widgets.py
index 44e88cf3df..2690ba57ab 100644
--- a/gui/wxpython/vnet/widgets.py
+++ b/gui/wxpython/vnet/widgets.py
@@ -532,7 +532,7 @@ class PointsList(
return False
- def IsShown(self, colName):
+ def IsShown(self, colName) -> bool:
"""Is column shown
:param colName: name of column
@@ -542,10 +542,7 @@ class PointsList(
:return: False - if is not shown
"""
- if self._getColumnNum(colName) == -1:
- return False
- else:
- return True
+ return not self._getColumnNum(colName) == -1
class EditItem(wx.Dialog):
diff --git a/gui/wxpython/web_services/cap_interface.py b/gui/wxpython/web_services/cap_interface.py
index 51ef21c439..4287375dd4 100644
--- a/gui/wxpython/web_services/cap_interface.py
+++ b/gui/wxpython/web_services/cap_interface.py
@@ -182,10 +182,7 @@ class WMSLayer(LayerBase):
name = self.xml_ns.Ns("Name")
name_node = self.layer_node.find(name)
- if name_node is not None:
- return True
- else:
- return False
+ return name_node is not None
class WMTSCapabilities(CapabilitiesBase, WMTSCapabilitiesTree):
@@ -307,12 +304,9 @@ class WMTSLayer(LayerBase):
layer_projs.append(mat_set_srs)
return layer_projs
- def IsRequestable(self):
+ def IsRequestable(self) -> bool:
"""Is it possible to use the layer for WMTS request?"""
- if self.layer_node is None:
- return False
- else:
- return True
+ return self.layer_node is not None
class OnEarthCapabilities(CapabilitiesBase, OnEarthCapabilitiesTree):
@@ -364,12 +358,9 @@ class OnEarthLayer(LayerBase):
self.child_layers = []
self.parent_layer = parent_layer
- def IsRequestable(self):
+ def IsRequestable(self) -> bool:
"""Is it possible to use the layer for NASA OnEarth GetMap request?"""
- if self.layer_node is None or self.layer_node.tag == "TiledGroups":
- return False
- else:
- return True
+ return not (self.layer_node is None or self.layer_node.tag == "TiledGroups")
def GetLayerData(self, param):
"""Get layer data"""
diff --git a/gui/wxpython/web_services/widgets.py b/gui/wxpython/web_services/widgets.py
index 200d5521b7..67d000d75d 100644
--- a/gui/wxpython/web_services/widgets.py
+++ b/gui/wxpython/web_services/widgets.py
@@ -1088,18 +1088,21 @@ class LayersList(TreeCtrl):
"""
def checknext(root_item, l_st_list, items_to_sel):
- def compare(item, l_name, st_name):
+ def compare(item, l_name, st_name) -> bool:
it_l_name = self.GetItemData(item)["layer"].GetLayerData("name")
it_st = self.GetItemData(item)["style"]
it_type = self.GetItemData(item)["type"]
- if it_l_name == l_name and (
- (not it_st and not st_name)
- or (it_st and it_st["name"] == st_name and it_type == "style")
- ):
- return True
-
- return False
+ return bool(
+ it_l_name == l_name
+ and (
+ not it_st
+ and not st_name
+ or it_st
+ and it_st["name"] == st_name
+ and it_type == "style"
+ )
+ )
(child, cookie) = self.GetFirstChild(root_item)
while child.IsOk():
diff --git a/lib/init/grass.py b/lib/init/grass.py
index dac7a6d818..1231e29904 100755
--- a/lib/init/grass.py
+++ b/lib/init/grass.py
@@ -730,12 +730,10 @@ def create_location(gisdbase, location, geostring):
fatal(err.value.strip('"').strip("'").replace("\\n", os.linesep))
-def can_create_location(gisdbase, location):
+def can_create_location(gisdbase, location) -> bool:
"""Checks if location can be created"""
path = os.path.join(gisdbase, location)
- if os.path.exists(path):
- return False
- return True
+ return not os.path.exists(path)
def cannot_create_location_reason(gisdbase, location):
diff --git a/man/build_class_graphical.py b/man/build_class_graphical.py
index 4e295bb18f..955f5c2a63 100644
--- a/man/build_class_graphical.py
+++ b/man/build_class_graphical.py
@@ -97,17 +97,15 @@ def file_matches(filename, patterns):
return False
-def starts_with_module(string, module):
+def starts_with_module(string, module) -> bool:
# not solving:
# module = module.replace('wxGUI.', 'g.gui.')
# TODO: matches g.mapsets images for g.mapset and d.rast.num for d.rast
- if string.startswith(module.replace(".", "_")):
- return True
- if string.startswith(module.replace(".", "")):
- return True
- if string.startswith(module):
- return True
- return False
+ return bool(
+ string.startswith(module.replace(".", "_"))
+ or string.startswith(module.replace(".", ""))
+ or string.startswith(module)
+ )
def get_module_image(module, images):
diff --git a/man/build_manual_gallery.py b/man/build_manual_gallery.py
index ea1ffb449c..3d381e2787 100755
--- a/man/build_manual_gallery.py
+++ b/man/build_manual_gallery.py
@@ -94,13 +94,11 @@ header_graphical_index_tmpl = """\
"""
-def img_in_html(filename, imagename):
+def img_in_html(filename, imagename) -> bool:
# for some reason, calling search just once is much faster
# than calling it on every line (time is spent in _compile)
pattern = re.compile("".format(imagename))
- if re.search(pattern, Path(filename).read_text()):
- return True
- return False
+ return bool(re.search(pattern, Path(filename).read_text()))
def file_matches(filename, patterns):
diff --git a/pyproject.toml b/pyproject.toml
index 21afb25d78..574b99df4c 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -268,7 +268,6 @@ ignore = [
"S608", # hardcoded-sql-expression
"SIM101", # duplicate-isinstance-call
"SIM102", # collapsible-if
- "SIM103", # needless-bool
"SIM105", # suppressible-exception
"SIM108", # if-else-block-instead-of-if-exp
"SIM109", # compare-with-tuple
diff --git a/python/grass/app/data.py b/python/grass/app/data.py
index ed7573c82d..439a6c3c4d 100644
--- a/python/grass/app/data.py
+++ b/python/grass/app/data.py
@@ -122,7 +122,7 @@ def _copy_startup_location(startup_location, location_in_grassdb):
return False
-def create_startup_location_in_grassdb(grassdatabase, startup_location_name):
+def create_startup_location_in_grassdb(grassdatabase, startup_location_name) -> bool:
"""Create a new startup location in the given GRASS database.
Returns True if a new startup location successfully created
@@ -137,9 +137,7 @@ def create_startup_location_in_grassdb(grassdatabase, startup_location_name):
# Copy the simple startup_location with some data to GRASS database
location_in_grassdb = os.path.join(grassdatabase, startup_location_name)
- if _copy_startup_location(startup_location, location_in_grassdb):
- return True
- return False
+ return bool(_copy_startup_location(startup_location, location_in_grassdb))
def ensure_default_data_hierarchy():
diff --git a/python/grass/grassdb/checks.py b/python/grass/grassdb/checks.py
index b8748de987..4de65a4cba 100644
--- a/python/grass/grassdb/checks.py
+++ b/python/grass/grassdb/checks.py
@@ -85,24 +85,20 @@ def is_location_valid(path, location=None):
return os.access(os.path.join(path, "PERMANENT", "DEFAULT_WIND"), os.F_OK)
-def is_mapset_current(database, location, mapset):
+def is_mapset_current(database, location, mapset) -> bool:
"""Return True if the given GRASS Mapset is the current mapset"""
genv = gisenv()
- if (
+ return bool(
database == genv["GISDBASE"]
and location == genv["LOCATION_NAME"]
and mapset == genv["MAPSET"]
- ):
- return True
- return False
+ )
-def is_location_current(database, location):
+def is_location_current(database, location) -> bool:
"""Return True if the given GRASS Location is the current location"""
genv = gisenv()
- if database == genv["GISDBASE"] and location == genv["LOCATION_NAME"]:
- return True
- return False
+ return bool(database == genv["GISDBASE"] and location == genv["LOCATION_NAME"])
def is_current_user_mapset_owner(mapset_path):
@@ -207,15 +203,13 @@ def get_mapset_lock_info(mapset_path):
return info
-def can_start_in_mapset(mapset_path, ignore_lock=False):
+def can_start_in_mapset(mapset_path, ignore_lock: bool = False) -> bool:
"""Check if a mapset from a gisrc file is usable for new session"""
- if not is_mapset_valid(mapset_path):
- return False
- if not is_current_user_mapset_owner(mapset_path):
- return False
- if not ignore_lock and is_mapset_locked(mapset_path):
- return False
- return True
+ return not (
+ (not is_mapset_valid(mapset_path))
+ or (not is_current_user_mapset_owner(mapset_path))
+ or (not ignore_lock and is_mapset_locked(mapset_path))
+ )
def get_reason_id_mapset_not_usable(mapset_path):
diff --git a/python/grass/grassdb/data.py b/python/grass/grassdb/data.py
index 49696b155e..980b0f02ff 100644
--- a/python/grass/grassdb/data.py
+++ b/python/grass/grassdb/data.py
@@ -12,7 +12,7 @@ for details.
import grass.script as gs
-def map_exists(name, element, mapset=None, env=None):
+def map_exists(name, element, mapset=None, env=None) -> bool:
"""Check is map is present in the mapset given in the environment
:param name: Name of the map
@@ -42,6 +42,4 @@ def map_exists(name, element, mapset=None, env=None):
info = gs.parse_key_val(output, sep="=")
# file is the key questioned in grass.script.core find_file()
# return code should be equivalent to checking the output
- if info["file"]:
- return True
- return False
+ return bool(info["file"])
diff --git a/python/grass/gunittest/checkers.py b/python/grass/gunittest/checkers.py
index 76f8100577..fb46a1deb6 100644
--- a/python/grass/gunittest/checkers.py
+++ b/python/grass/gunittest/checkers.py
@@ -495,7 +495,7 @@ def proj_units_equals(text_a, text_b):
# TODO: change checking over lines?
# TODO: change parameter order?
# TODO: the behavior with last \n is strange but now using DOTALL and $
-def check_text_ellipsis(reference, actual):
+def check_text_ellipsis(reference, actual) -> bool:
r"""
>>> check_text_ellipsis(
... "Vector map <...> contains ... points.",
@@ -537,10 +537,7 @@ def check_text_ellipsis(reference, actual):
ref_escaped = re.escape(reference)
exp = re.compile(r"\\\.\\\.\\\.") # matching escaped ...
ref_regexp = exp.sub(".+", ref_escaped) + "$"
- if re.match(ref_regexp, actual, re.DOTALL):
- return True
- else:
- return False
+ return bool(re.match(ref_regexp, actual, re.DOTALL))
def check_text_ellipsis_doctest(reference, actual):
diff --git a/python/grass/gunittest/gutils.py b/python/grass/gunittest/gutils.py
index 16618e729f..ca5b8f7b43 100644
--- a/python/grass/gunittest/gutils.py
+++ b/python/grass/gunittest/gutils.py
@@ -21,7 +21,7 @@ def get_current_mapset():
return call_module("g.mapset", flags="p").strip()
-def is_map_in_mapset(name, type, mapset=None):
+def is_map_in_mapset(name, type, mapset=None) -> bool:
"""Check is map is present in the mapset (current mapset by default)
This function is different from what we would expect in GRASS
@@ -60,7 +60,4 @@ def is_map_in_mapset(name, type, mapset=None):
info = text_to_keyvalue(decode(output), sep="=")
# file is the key questioned in grass.script.core find_file()
# return code should be equivalent to checking the output
- if info["file"]:
- return True
- else:
- return False
+ return bool(info["file"])
diff --git a/python/grass/pygrass/utils.py b/python/grass/pygrass/utils.py
index e8f4ce68a4..d9d17ade0d 100644
--- a/python/grass/pygrass/utils.py
+++ b/python/grass/pygrass/utils.py
@@ -174,7 +174,7 @@ def get_mapset_vector(mapname, mapset=""):
return decode(libgis.G_find_vector2(mapname, mapset))
-def is_clean_name(name):
+def is_clean_name(name) -> bool:
"""Return if the name is valid
>>> is_clean_name("census")
@@ -187,9 +187,7 @@ def is_clean_name(name):
False
"""
- if libgis.G_legal_filename(name) < 0:
- return False
- return True
+ return not libgis.G_legal_filename(name) < 0
def coor2pixel(coord, region):
diff --git a/python/grass/script/core.py b/python/grass/script/core.py
index 20d3f358a8..d46c35d335 100644
--- a/python/grass/script/core.py
+++ b/python/grass/script/core.py
@@ -1192,7 +1192,7 @@ def gisenv(env=None):
# interface to g.region
-def locn_is_latlong(env=None):
+def locn_is_latlong(env=None) -> bool:
"""Tests if location is lat/long. Value is obtained
by checking the "g.region -pu" projection code.
@@ -1200,10 +1200,7 @@ def locn_is_latlong(env=None):
"""
s = read_command("g.region", flags="pu", env=env)
kv = parse_key_val(s, ":")
- if kv["projection"].split(" ")[0] == "3":
- return True
- else:
- return False
+ return kv["projection"].split(" ")[0] == "3"
def region(region3d=False, complete=False, env=None):
diff --git a/python/grass/temporal/abstract_dataset.py b/python/grass/temporal/abstract_dataset.py
index f8b9a5e1cc..cfe3c83a84 100644
--- a/python/grass/temporal/abstract_dataset.py
+++ b/python/grass/temporal/abstract_dataset.py
@@ -301,7 +301,7 @@ class AbstractDataset(
"""
return self.relative_time.get_unit()
- def check_relative_time_unit(self, unit):
+ def check_relative_time_unit(self, unit) -> bool:
"""Check if unit is of type year(s), month(s), day(s), hour(s),
minute(s) or second(s)
@@ -323,9 +323,7 @@ class AbstractDataset(
"second",
"seconds",
]
- if unit not in units:
- return False
- return True
+ return not unit not in units
def get_temporal_type(self):
"""Return the temporal type of this dataset
diff --git a/python/grass/temporal/base.py b/python/grass/temporal/base.py
index f4175c7713..9296a22dfa 100644
--- a/python/grass/temporal/base.py
+++ b/python/grass/temporal/base.py
@@ -313,7 +313,7 @@ class SQLDatabaseInterface(DictSQLSerializer):
+ "';\n"
)
- def is_in_db(self, dbif=None, mapset=None):
+ def is_in_db(self, dbif=None, mapset=None) -> bool:
"""Check if this object is present in the temporal database
:param dbif: The database interface to be used,
@@ -342,10 +342,7 @@ class SQLDatabaseInterface(DictSQLSerializer):
dbif.close()
# Nothing found
- if row is None:
- return False
-
- return True
+ return row is not None
def get_select_statement(self):
"""Return the sql statement and the argument list in
diff --git a/python/grass/temporal/spatial_extent.py b/python/grass/temporal/spatial_extent.py
index 6c025fb7a4..329a0a4a68 100644
--- a/python/grass/temporal/spatial_extent.py
+++ b/python/grass/temporal/spatial_extent.py
@@ -143,7 +143,7 @@ class SpatialExtent(SQLDatabaseInterface):
self.set_spatial_extent_from_values(north, south, east, west, top, bottom)
self.set_projection(proj)
- def overlapping_2d(self, extent):
+ def overlapping_2d(self, extent) -> bool:
"""Return True if this (A) and the provided spatial extent (B) overlaps
in two dimensional space.
Code is lend from wind_overlap.c in lib/gis
@@ -191,21 +191,14 @@ class SpatialExtent(SQLDatabaseInterface):
E -= 360.0
W -= 360.0
- if self.get_north() <= S:
- return False
+ return not (
+ self.get_north() <= S
+ or self.get_south() >= N
+ or self.get_east() <= W
+ or self.get_west() >= E
+ )
- if self.get_south() >= N:
- return False
-
- if self.get_east() <= W:
- return False
-
- if self.get_west() >= E:
- return False
-
- return True
-
- def overlapping(self, extent):
+ def overlapping(self, extent) -> bool:
"""Return True if this (A) and the provided spatial
extent (B) overlaps in three dimensional space.
@@ -240,13 +233,7 @@ class SpatialExtent(SQLDatabaseInterface):
T = extent.get_top()
B = extent.get_bottom()
- if self.get_top() <= B:
- return False
-
- if self.get_bottom() >= T:
- return False
-
- return True
+ return not (self.get_top() <= B or self.get_bottom() >= T)
def intersect_2d(self, extent):
"""Return the two dimensional intersection as spatial_extent
@@ -592,7 +579,7 @@ class SpatialExtent(SQLDatabaseInterface):
return new
- def is_in_2d(self, extent):
+ def is_in_2d(self, extent) -> bool:
"""Return True if this extent (A) is located in the provided spatial
extent (B) in two dimensions.
@@ -636,18 +623,9 @@ class SpatialExtent(SQLDatabaseInterface):
eE -= 360.0
eW -= 360.0
- if eW >= W:
- return False
- if eE <= E:
- return False
- if eN <= N:
- return False
- if eS >= S:
- return False
+ return not (eW >= W or eE <= E or eN <= N or eS >= S)
- return True
-
- def is_in(self, extent):
+ def is_in(self, extent) -> bool:
"""Return True if this extent (A) is located in the provided spatial
extent (B) in three dimensions.
@@ -678,12 +656,7 @@ class SpatialExtent(SQLDatabaseInterface):
T = self.get_top()
B = self.get_bottom()
- if eB >= B:
- return False
- if eT <= T:
- return False
-
- return True
+ return not (eB >= B or eT <= T)
def contain_2d(self, extent):
"""Return True if this extent (A) contains the provided spatial
@@ -729,7 +702,7 @@ class SpatialExtent(SQLDatabaseInterface):
"""
return extent.is_in(self)
- def equivalent_2d(self, extent):
+ def equivalent_2d(self, extent) -> bool:
"""Return True if this extent (A) is equal to the provided spatial
extent (B) in two dimensions.
@@ -776,18 +749,9 @@ class SpatialExtent(SQLDatabaseInterface):
eE -= 360.0
eW -= 360.0
- if eW != W:
- return False
- if eE != E:
- return False
- if eN != N:
- return False
- if eS != S:
- return False
+ return not (eW != W or eE != E or eN != N or eS != S)
- return True
-
- def equivalent(self, extent):
+ def equivalent(self, extent) -> bool:
"""Return True if this extent (A) is equal to the provided spatial
extent (B) in three dimensions.
@@ -819,14 +783,9 @@ class SpatialExtent(SQLDatabaseInterface):
T = self.get_top()
B = self.get_bottom()
- if eB != B:
- return False
- if eT != T:
- return False
+ return not (eB != B or eT != T)
- return True
-
- def cover_2d(self, extent):
+ def cover_2d(self, extent) -> bool:
"""Return True if this extent (A) covers the provided spatial
extent (B) in two dimensions.
@@ -916,12 +875,9 @@ class SpatialExtent(SQLDatabaseInterface):
if eS > S and eS < N:
edge_count += 1
- if edge_count == 0:
- return False
+ return not edge_count == 0
- return True
-
- def cover(self, extent):
+ def cover(self, extent) -> bool:
"""Return True if this extent covers the provided spatial
extent in three dimensions.
@@ -974,17 +930,7 @@ class SpatialExtent(SQLDatabaseInterface):
eW -= 360.0
# Edges of extent located outside of self are not allowed
- if eW >= E:
- return False
- if eE <= W:
- return False
- if eS >= N:
- return False
- if eN <= S:
- return False
- if eB >= T:
- return False
- if eT <= B:
+ if (eW >= E) or (eE <= W) or (eS >= N) or (eN <= S) or (eB >= T) or (eT <= B):
return False
# First we check that at least one edge of extent meets an edge of self
@@ -1010,10 +956,7 @@ class SpatialExtent(SQLDatabaseInterface):
if eB > B and eB < T:
edge_count += 1
- if edge_count == 0:
- return False
-
- return True
+ return not edge_count == 0
def covered_2d(self, extent):
"""Return True if this extent is covered by the provided spatial
@@ -1047,7 +990,7 @@ class SpatialExtent(SQLDatabaseInterface):
return extent.cover(self)
- def overlap_2d(self, extent):
+ def overlap_2d(self, extent) -> bool:
"""Return True if this extent (A) overlaps with the provided spatial
extent (B) in two dimensions.
Code is lend from wind_overlap.c in lib/gis
@@ -1103,21 +1046,14 @@ class SpatialExtent(SQLDatabaseInterface):
E -= 360.0
W -= 360.0
- if self.get_north() <= S:
- return False
+ return not (
+ self.get_north() <= S
+ or self.get_south() >= N
+ or self.get_east() <= W
+ or self.get_west() >= E
+ )
- if self.get_south() >= N:
- return False
-
- if self.get_east() <= W:
- return False
-
- if self.get_west() >= E:
- return False
-
- return True
-
- def overlap(self, extent):
+ def overlap(self, extent) -> bool:
"""Return True if this extent overlaps with the provided spatial
extent in three dimensions.
@@ -1165,25 +1101,14 @@ class SpatialExtent(SQLDatabaseInterface):
E -= 360.0
W -= 360.0
- if self.get_north() <= S:
- return False
-
- if self.get_south() >= N:
- return False
-
- if self.get_east() <= W:
- return False
-
- if self.get_west() >= E:
- return False
-
- if self.get_top() <= B:
- return False
-
- if self.get_bottom() >= T:
- return False
-
- return True
+ return not (
+ self.get_north() <= S
+ or self.get_south() >= N
+ or self.get_east() <= W
+ or self.get_west() >= E
+ or self.get_top() <= B
+ or self.get_bottom() >= T
+ )
def meet_2d(self, extent):
"""Return True if this extent (A) meets with the provided spatial
@@ -1270,7 +1195,7 @@ class SpatialExtent(SQLDatabaseInterface):
return True
- def meet(self, extent):
+ def meet(self, extent) -> bool:
"""Return True if this extent meets with the provided spatial
extent in three dimensions.
@@ -1350,7 +1275,7 @@ class SpatialExtent(SQLDatabaseInterface):
return True
- def disjoint_2d(self, extent):
+ def disjoint_2d(self, extent) -> bool:
"""Return True if this extent (A) is disjoint with the provided spatial
extent (B) in three dimensions.
@@ -1368,28 +1293,15 @@ class SpatialExtent(SQLDatabaseInterface):
:return: True or False
"""
- if self.is_in_2d(extent):
- return False
-
- if self.contain_2d(extent):
- return False
-
- if self.cover_2d(extent):
- return False
-
- if self.covered_2d(extent):
- return False
-
- if self.equivalent_2d(extent):
- return False
-
- if self.overlapping_2d(extent):
- return False
-
- if self.meet_2d(extent):
- return False
-
- return True
+ return not (
+ self.is_in_2d(extent)
+ or self.contain_2d(extent)
+ or self.cover_2d(extent)
+ or self.covered_2d(extent)
+ or self.equivalent_2d(extent)
+ or self.overlapping_2d(extent)
+ or self.meet_2d(extent)
+ )
def disjoint(self, extent):
"""Return True if this extent is disjoint with the provided spatial
@@ -1399,28 +1311,15 @@ class SpatialExtent(SQLDatabaseInterface):
:return: True or False
"""
- if self.is_in(extent):
- return False
-
- if self.contain(extent):
- return False
-
- if self.cover(extent):
- return False
-
- if self.covered(extent):
- return False
-
- if self.equivalent(extent):
- return False
-
- if self.overlapping(extent):
- return False
-
- if self.meet(extent):
- return False
-
- return True
+ return not (
+ self.is_in(extent)
+ or self.contain(extent)
+ or self.cover(extent)
+ or self.covered(extent)
+ or self.equivalent(extent)
+ or self.overlapping(extent)
+ or self.meet(extent)
+ )
def spatial_relation_2d(self, extent):
"""Returns the two dimensional spatial relation between this
diff --git a/python/grass/temporal/temporal_extent.py b/python/grass/temporal/temporal_extent.py
index fd9c63db2f..42cce4599b 100644
--- a/python/grass/temporal/temporal_extent.py
+++ b/python/grass/temporal/temporal_extent.py
@@ -428,7 +428,7 @@ class TemporalExtent(SQLDatabaseInterface):
return self.disjoint_union(extent)
- def starts(self, extent):
+ def starts(self, extent) -> bool:
"""Return True if this temporal extent (A) starts at the start of the
provided temporal extent (B) and finishes within it
::
@@ -455,15 +455,12 @@ class TemporalExtent(SQLDatabaseInterface):
if self.D["end_time"] is None or extent.D["end_time"] is None:
return False
- if (
+ return bool(
self.D["start_time"] == extent.D["start_time"]
and self.D["end_time"] < extent.D["end_time"]
- ):
- return True
- else:
- return False
+ )
- def started(self, extent):
+ def started(self, extent) -> bool:
"""Return True if this temporal extent (A) started at the start of the
provided temporal extent (B) and finishes after it
::
@@ -489,15 +486,12 @@ class TemporalExtent(SQLDatabaseInterface):
if self.D["end_time"] is None or extent.D["end_time"] is None:
return False
- if (
+ return bool(
self.D["start_time"] == extent.D["start_time"]
and self.D["end_time"] > extent.D["end_time"]
- ):
- return True
- else:
- return False
+ )
- def finishes(self, extent):
+ def finishes(self, extent) -> bool:
"""Return True if this temporal extent (A) starts after the start of
the provided temporal extent (B) and finishes with it
::
@@ -523,15 +517,12 @@ class TemporalExtent(SQLDatabaseInterface):
if self.D["end_time"] is None or extent.D["end_time"] is None:
return False
- if (
+ return bool(
self.D["end_time"] == extent.D["end_time"]
and self.D["start_time"] > extent.D["start_time"]
- ):
- return True
- else:
- return False
+ )
- def finished(self, extent):
+ def finished(self, extent) -> bool:
"""Return True if this temporal extent (A) starts before the start of
the provided temporal extent (B) and finishes with it
::
@@ -557,15 +548,12 @@ class TemporalExtent(SQLDatabaseInterface):
if self.D["end_time"] is None or extent.D["end_time"] is None:
return False
- if (
+ return bool(
self.D["end_time"] == extent.D["end_time"]
and self.D["start_time"] < extent.D["start_time"]
- ):
- return True
- else:
- return False
+ )
- def after(self, extent):
+ def after(self, extent) -> bool:
"""Return True if this temporal extent (A) is located after the
provided temporal extent (B)
::
@@ -589,15 +577,9 @@ class TemporalExtent(SQLDatabaseInterface):
"""
if extent.D["end_time"] is None:
- if self.D["start_time"] > extent.D["start_time"]:
- return True
- else:
- return False
+ return self.D["start_time"] > extent.D["start_time"]
- if self.D["start_time"] > extent.D["end_time"]:
- return True
- else:
- return False
+ return self.D["start_time"] > extent.D["end_time"]
def before(self, extent):
"""Return True if this temporal extent (A) is located before the
@@ -623,17 +605,11 @@ class TemporalExtent(SQLDatabaseInterface):
"""
if self.D["end_time"] is None:
- if self.D["start_time"] < extent.D["start_time"]:
- return True
- else:
- return False
+ return self.D["start_time"] < extent.D["start_time"]
- if self.D["end_time"] < extent.D["start_time"]:
- return True
- else:
- return False
+ return self.D["end_time"] < extent.D["start_time"]
- def adjacent(self, extent):
+ def adjacent(self, extent) -> bool:
"""Return True if this temporal extent (A) is a meeting neighbor the
provided temporal extent (B)
::
@@ -667,14 +643,16 @@ class TemporalExtent(SQLDatabaseInterface):
if self.D["end_time"] is None and extent.D["end_time"] is None:
return False
- if (self.D["start_time"] == extent.D["end_time"]) or (
- self.D["end_time"] == extent.D["start_time"]
- ):
- return True
- else:
- return False
+ return bool(
+ self.D["start_time"] is not None
+ and extent.D["end_time"] is not None
+ and (
+ self.D["start_time"] == extent.D["end_time"]
+ or self.D["end_time"] == extent.D["start_time"]
+ )
+ )
- def follows(self, extent):
+ def follows(self, extent) -> bool:
"""Return True if this temporal extent (A) follows the
provided temporal extent (B)
::
@@ -697,15 +675,12 @@ class TemporalExtent(SQLDatabaseInterface):
False
"""
- if extent.D["end_time"] is None:
- return False
+ return (
+ extent.D["end_time"] is not None
+ and self.D["start_time"] == extent.D["end_time"]
+ )
- if self.D["start_time"] == extent.D["end_time"]:
- return True
- else:
- return False
-
- def precedes(self, extent):
+ def precedes(self, extent) -> bool:
"""Return True if this temporal extent (A) precedes the provided
temporal extent (B)
::
@@ -730,15 +705,12 @@ class TemporalExtent(SQLDatabaseInterface):
"""
- if self.D["end_time"] is None:
- return False
+ return (
+ self.D["end_time"] is not None
+ and self.D["end_time"] == extent.D["start_time"]
+ )
- if self.D["end_time"] == extent.D["start_time"]:
- return True
- else:
- return False
-
- def during(self, extent):
+ def during(self, extent) -> bool:
"""Return True if this temporal extent (A) is located during the provided
temporal extent (B)
::
@@ -766,23 +738,17 @@ class TemporalExtent(SQLDatabaseInterface):
# Check single point of time in interval
if self.D["end_time"] is None:
- if (
+ return bool(
self.D["start_time"] >= extent.D["start_time"]
and self.D["start_time"] < extent.D["end_time"]
- ):
- return True
- else:
- return False
+ )
- if (
+ return bool(
self.D["start_time"] > extent.D["start_time"]
and self.D["end_time"] < extent.D["end_time"]
- ):
- return True
- else:
- return False
+ )
- def contains(self, extent):
+ def contains(self, extent) -> bool:
"""Return True if this temporal extent (A) contains the provided
temporal extent (B)
::
@@ -811,23 +777,17 @@ class TemporalExtent(SQLDatabaseInterface):
# Check single point of time in interval
if extent.D["end_time"] is None:
- if (
+ return bool(
self.D["start_time"] <= extent.D["start_time"]
and self.D["end_time"] > extent.D["start_time"]
- ):
- return True
- else:
- return False
+ )
- if (
+ return bool(
self.D["start_time"] < extent.D["start_time"]
and self.D["end_time"] > extent.D["end_time"]
- ):
- return True
- else:
- return False
+ )
- def equal(self, extent):
+ def equal(self, extent) -> bool:
"""Return True if this temporal extent (A) is equal to the provided
temporal extent (B)
::
@@ -851,23 +811,17 @@ class TemporalExtent(SQLDatabaseInterface):
"""
if self.D["end_time"] is None and extent.D["end_time"] is None:
- if self.D["start_time"] == extent.D["start_time"]:
- return True
- else:
- return False
+ return self.D["start_time"] == extent.D["start_time"]
if self.D["end_time"] is None or extent.D["end_time"] is None:
return False
- if (
+ return bool(
self.D["start_time"] == extent.D["start_time"]
and self.D["end_time"] == extent.D["end_time"]
- ):
- return True
- else:
- return False
+ )
- def overlaps(self, extent):
+ def overlaps(self, extent) -> bool:
"""Return True if this temporal extent (A) overlapped the provided
temporal extent (B)
::
@@ -897,19 +851,16 @@ class TemporalExtent(SQLDatabaseInterface):
False
"""
- if self.D["end_time"] is None or extent.D["end_time"] is None:
- return False
- if (
- self.D["start_time"] < extent.D["start_time"]
+ return bool(
+ self.D["end_time"] is not None
+ and extent.D["end_time"] is not None
+ and self.D["start_time"] < extent.D["start_time"]
and self.D["end_time"] < extent.D["end_time"]
and self.D["end_time"] > extent.D["start_time"]
- ):
- return True
- else:
- return False
+ )
- def overlapped(self, extent):
+ def overlapped(self, extent) -> bool:
"""Return True if this temporal extent (A) overlapps the provided
temporal extent (B)
::
@@ -940,17 +891,14 @@ class TemporalExtent(SQLDatabaseInterface):
False
"""
- if self.D["end_time"] is None or extent.D["end_time"] is None:
- return False
- if (
- self.D["start_time"] > extent.D["start_time"]
+ return bool(
+ self.D["end_time"] is not None
+ and extent.D["end_time"] is not None
+ and self.D["start_time"] > extent.D["start_time"]
and self.D["end_time"] > extent.D["end_time"]
and self.D["start_time"] < extent.D["end_time"]
- ):
- return True
- else:
- return False
+ )
def temporal_relation(self, extent):
"""Returns the temporal relation between temporal objects
diff --git a/python/grass/temporal/temporal_granularity.py b/python/grass/temporal/temporal_granularity.py
index d66f6c57ff..29836959cb 100644
--- a/python/grass/temporal/temporal_granularity.py
+++ b/python/grass/temporal/temporal_granularity.py
@@ -150,7 +150,7 @@ def get_time_tuple_function(maps):
return _get_row_time_tuple
-def _is_after(start, start1, end1):
+def _is_after(start, start1, end1) -> bool:
"""Helper function that checks if start timestamp is
temporally after the start1 and end1, where start1 and end1
represent a temporal extent.
@@ -177,15 +177,9 @@ def _is_after(start, start1, end1):
"""
if end1 is None:
- if start > start1:
- return True
- else:
- return False
+ return start > start1
- if start > end1:
- return True
- else:
- return False
+ return start > end1
def compute_relative_time_granularity(maps):
diff --git a/scripts/g.search.modules/g.search.modules.py b/scripts/g.search.modules/g.search.modules.py
index e96600e149..89ea482bc5 100755
--- a/scripts/g.search.modules/g.search.modules.py
+++ b/scripts/g.search.modules/g.search.modules.py
@@ -286,23 +286,22 @@ def _search_module(
return sorted(found_modules, key=lambda k: k["name"])
-def _basic_search(pattern, name, description, module_keywords):
+def _basic_search(pattern, name, description, module_keywords) -> bool:
"""Search for a string in all the provided strings.
This lowercases the strings before searching in them, so the pattern
string should be lowercased too.
"""
- if name and description and module_keywords:
- if (
+ return bool(
+ name
+ and description
+ and module_keywords
+ and (
name.lower().find(pattern) > -1
or description.lower().find(pattern) > -1
or module_keywords.lower().find(pattern) > -1
- ):
- return True
- else:
- return False
- else:
- return False
+ )
+ )
def _exact_search(keyword, module_keywords):
diff --git a/scripts/r.in.wms/wms_cap_parsers.py b/scripts/r.in.wms/wms_cap_parsers.py
index 5435fe2959..56d6e788e3 100644
--- a/scripts/r.in.wms/wms_cap_parsers.py
+++ b/scripts/r.in.wms/wms_cap_parsers.py
@@ -350,7 +350,7 @@ class WMTSCapabilitiesTree(BaseCapabilitiesTree):
gs.debug("Check of WMTS capabilities tree was finished.", 4)
- def _checkMatSet(self, mat_set):
+ def _checkMatSet(self, mat_set) -> bool:
"""!Check ."""
mat_set_id = mat_set.find(self.xml_ns.NsOws("Identifier"))
if mat_set_id is None or not mat_set_id.text:
@@ -370,15 +370,12 @@ class WMTSCapabilitiesTree(BaseCapabilitiesTree):
mat_set.remove(t_mat)
tile_mats = mat_set.findall(self.xml_ns.NsWmts("TileMatrix"))
- if not tile_mats:
- return False
-
- return True
+ return bool(tile_mats)
def _checkMat(self, t_mat):
"""!Check ."""
- def _checkElement(t_mat, e, func):
+ def _checkElement(t_mat, e, func) -> bool:
element = t_mat.find(self.xml_ns.NsWmts(e))
if element is None or not element.text:
return False
@@ -388,9 +385,7 @@ class WMTSCapabilitiesTree(BaseCapabilitiesTree):
except ValueError:
return False
- if e < 0:
- return False
- return True
+ return not e < 0
for e, func in [
["ScaleDenominator", float],
@@ -450,7 +445,7 @@ class WMTSCapabilitiesTree(BaseCapabilitiesTree):
return True
- def _checkMatSetLink(self, link, mat_sets):
+ def _checkMatSetLink(self, link, mat_sets) -> bool:
"""!Check element."""
mat_set_link_id = link.find(self.xml_ns.NsWmts("TileMatrixSet")).text
found = False
@@ -484,10 +479,7 @@ class WMTSCapabilitiesTree(BaseCapabilitiesTree):
gs.debug("Removed invalid element.", 4)
link.remove(tile_mat_set_limits)
- if not found:
- return False
-
- return True
+ return found
def _checkMatSetLimit(self, limit):
"""!Check element."""
@@ -604,7 +596,7 @@ class OnEarthCapabilitiesTree(BaseCapabilitiesTree):
return res
- def _checkLayer(self, layer):
+ def _checkLayer(self, layer) -> bool:
"""!Check / elements."""
if layer.tag == "TiledGroups":
return True
@@ -628,10 +620,7 @@ class OnEarthCapabilitiesTree(BaseCapabilitiesTree):
patt.text = "\n".join(urls)
t_patts = layer.findall("TilePattern")
- if not t_patts:
- return False
-
- return True
+ return bool(t_patts)
def _getUrls(self, tile_pattern):
"""!Get all urls from tile pattern."""
diff --git a/scripts/r.in.wms/wms_drv.py b/scripts/r.in.wms/wms_drv.py
index 2f92ec4538..4628c60b8e 100644
--- a/scripts/r.in.wms/wms_drv.py
+++ b/scripts/r.in.wms/wms_drv.py
@@ -439,11 +439,11 @@ class BaseRequestMgr:
self.tile_ref = {"sizeX": tile_size["x"], "sizeY": tile_size["y"]}
- def _isGeoProj(self, proj):
+ def _isGeoProj(self, proj) -> bool:
"""!Is it geographic projection?"""
- if proj.find("+proj=latlong") != -1 or proj.find("+proj=longlat") != -1:
- return True
- return False
+ return bool(
+ proj.find("+proj=latlong") != -1 or proj.find("+proj=longlat") != -1
+ )
class WMSRequestMgr(BaseRequestMgr):
diff --git a/scripts/r.tileset/r.tileset.py b/scripts/r.tileset/r.tileset.py
index f2049385a9..f5e7ab17b1 100644
--- a/scripts/r.tileset/r.tileset.py
+++ b/scripts/r.tileset/r.tileset.py
@@ -217,7 +217,7 @@ def sideLengths(points, xmetric, ymetric):
return {"x": (ret[1], ret[3]), "y": (ret[0], ret[2])}
-def bboxesIntersect(bbox_1, bbox_2):
+def bboxesIntersect(bbox_1, bbox_2) -> bool:
"""Determine if two bounding boxes intersect"""
bi_a1 = (bbox_1["w"], bbox_1["s"])
bi_a2 = (bbox_1["e"], bbox_1["n"])
@@ -233,10 +233,7 @@ def bboxesIntersect(bbox_1, bbox_2):
):
cin[i] = True
- if cin[0] and cin[1]:
- return True
-
- return False
+ return bool(cin[0] and cin[1])
def main():