Skip to content

Commit

Permalink
style: Fix negate-equal-op (SIM201) (#4407)
Browse files Browse the repository at this point in the history
* style: Fix negate-equal-op (SIM201)

Ruff rule: https://docs.astral.sh/ruff/rules/negate-equal-op/

* style: Fix repeated-equality-comparison (PLR1714) on changed code
  • Loading branch information
echoix committed Sep 28, 2024
1 parent fee26ec commit 49f67fd
Show file tree
Hide file tree
Showing 26 changed files with 44 additions and 45 deletions.
2 changes: 1 addition & 1 deletion gui/wxpython/animation/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ def _export_file_validation(self, filebrowsebtn, file_path, file_postfix):
caption=_("Overwrite?"),
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
)
if not overwrite_dlg.ShowModal() == wx.ID_YES:
if overwrite_dlg.ShowModal() != wx.ID_YES:
overwrite_dlg.Destroy()
return False
overwrite_dlg.Destroy()
Expand Down
10 changes: 5 additions & 5 deletions gui/wxpython/gcp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ def OnGeorect(self, event):
overwrite=self.overwrite,
)
if overwrite_dlg:
if not overwrite_dlg.ShowModal() == wx.ID_YES:
if overwrite_dlg.ShowModal() != wx.ID_YES:
overwrite_dlg.Destroy()
return
overwrite_dlg.Destroy()
Expand Down Expand Up @@ -1870,7 +1870,7 @@ def OnGeorect(self, event):
overwrite=self.overwrite,
)
if overwrite_dlg:
if not overwrite_dlg.ShowModal() == wx.ID_YES:
if overwrite_dlg.ShowModal() != wx.ID_YES:
overwrite_dlg.Destroy()
return
overwrite_dlg.Destroy()
Expand Down Expand Up @@ -2300,7 +2300,7 @@ def AdjustMap(self, newreg):
def OnZoomToSource(self, event):
"""Set target map window to match extents of source map window"""

if not self.MapWindow == self.TgtMapWindow:
if self.MapWindow != self.TgtMapWindow:
self.MapWindow = self.TgtMapWindow
self.Map = self.TgtMap
self.UpdateActive(self.TgtMapWindow)
Expand All @@ -2313,7 +2313,7 @@ def OnZoomToSource(self, event):
def OnZoomToTarget(self, event):
"""Set source map window to match extents of target map window"""

if not self.MapWindow == self.SrcMapWindow:
if self.MapWindow != self.SrcMapWindow:
self.MapWindow = self.SrcMapWindow
self.Map = self.SrcMap
self.UpdateActive(self.SrcMapWindow)
Expand Down Expand Up @@ -3323,7 +3323,7 @@ def OnSrcSelection(self, event):

tmp_map = self.srcselection.GetValue()

if not tmp_map == "" and not tmp_map == src_map:
if tmp_map not in ("", src_map):
self.new_src_map = tmp_map

def OnTgtRastSelection(self, event):
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gcp/mapdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def GetMapToolbar(self):
return self.toolbars["gcpdisp"]

def _setActiveMapWindow(self, mapWindow):
if not self.MapWindow == mapWindow:
if self.MapWindow != mapWindow:
self.MapWindow = mapWindow
self.Map = mapWindow.Map
self.UpdateActive(mapWindow)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gui_core/vselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def AddVecInfo(self, vInfoDictTMP) -> bool:
if self._dialog:
self.slist.AddItem(vInfoDictTMP)

return not len(self.selectedFeatures) == 0
return len(self.selectedFeatures) != 0

def _draw(self):
"""Call class 'VectorSelectHighlighter' to draw selected features"""
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/iclass/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def OnZoomMenu(self, event):
def OnZoomToTraining(self, event):
"""Set preview display to match extents of training display"""

if not self.MapWindow == self.GetSecondWindow():
if self.MapWindow != self.GetSecondWindow():
self.MapWindow = self.GetSecondWindow()
self.Map = self.GetSecondMap()
self.UpdateActive(self.GetSecondWindow())
Expand All @@ -583,7 +583,7 @@ def OnZoomToTraining(self, event):
def OnZoomToPreview(self, event):
"""Set preview display to match extents of training display"""

if not self.MapWindow == self.GetFirstWindow():
if self.MapWindow != self.GetFirstWindow():
self.MapWindow = self.GetFirstWindow()
self.Map = self.GetFirstMap()
self.UpdateActive(self.GetFirstWindow())
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/image2target/ii2t_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2245,7 +2245,7 @@ def AdjustMap(self, newreg):
def OnZoomToSource(self, event):
"""Set target map window to match extents of source map window"""

if not self.MapWindow == self.TgtMapWindow:
if self.MapWindow != self.TgtMapWindow:
self.MapWindow = self.TgtMapWindow
self.Map = self.TgtMap
self.UpdateActive(self.TgtMapWindow)
Expand All @@ -2258,7 +2258,7 @@ def OnZoomToSource(self, event):
def OnZoomToTarget(self, event):
"""Set source map window to match extents of target map window"""

if not self.MapWindow == self.SrcMapWindow:
if self.MapWindow != self.SrcMapWindow:
self.MapWindow = self.SrcMapWindow
self.Map = self.SrcMap
self.UpdateActive(self.SrcMapWindow)
Expand Down Expand Up @@ -3282,7 +3282,7 @@ def OnSrcSelection(self, event):

tmp_map = self.srcselection.GetValue()

if not tmp_map == "" and not tmp_map == src_map:
if tmp_map not in ("", src_map):
self.new_src_map = tmp_map

def OnTgtRastSelection(self, event):
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/image2target/ii2t_mapdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def GetMapToolbar(self):
return self.toolbars["gcpdisp"]

def _setActiveMapWindow(self, mapWindow):
if not self.MapWindow == mapWindow:
if self.MapWindow != mapWindow:
self.MapWindow = mapWindow
self.Map = mapWindow.Map
self.UpdateActive(mapWindow)
Expand Down
10 changes: 5 additions & 5 deletions gui/wxpython/iscatt/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def SetEmpty(self):
return self.polygon_drawer.SetEmpty()

def OnRelease(self, event):
if not self.mode == "zoom":
if self.mode != "zoom":
return
self.zoom_rect.set_visible(False)
self.ZoomRectangle(event)
Expand Down Expand Up @@ -348,7 +348,7 @@ def ZoomWheel(self, event):

def ZoomRectangle(self, event):
# get the current x and y limits
if not self.mode == "zoom":
if self.mode != "zoom":
return
if event.inaxes is None:
return
Expand Down Expand Up @@ -394,7 +394,7 @@ def OnCanvasLeave(self, event):

def PanMotion(self, event):
"on mouse movement"
if not self.mode == "pan":
if self.mode != "pan":
return
if event.inaxes is None:
return
Expand Down Expand Up @@ -426,7 +426,7 @@ def PanMotion(self, event):
self.canvas.draw()

def ZoomRectMotion(self, event):
if not self.mode == "zoom":
if self.mode != "zoom":
return
if event.inaxes is None:
return
Expand Down Expand Up @@ -866,7 +866,7 @@ def _addVertex(self, event):

def motion_notify_callback(self, event):
"on mouse movement"
if not self.mode == "move_vertex":
if self.mode != "move_vertex":
return
if not self.showverts:
return
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/mapdisp/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,15 +831,15 @@ def _DToRastDone():
overwrite=overwrite,
getErrorMsg=True,
)
if not returncode == 0:
if returncode != 0:
self._giface.WriteError(_("Failed to run d.to.rast:\n") + messages)
return
# set region for composite
gs.use_temp_region()
returncode, messages = RunCommand(
"g.region", raster=tmpName + ".red", quiet=True, getErrorMsg=True
)
if not returncode == 0:
if returncode != 0:
gs.del_temp_region()
self._giface.WriteError(_("Failed to run d.to.rast:\n") + messages)
return
Expand All @@ -862,7 +862,7 @@ def _DToRastDone():
quiet=True,
name=[tmpName + ".red", tmpName + ".green", tmpName + ".blue"],
)
if not returncode == 0:
if returncode != 0:
self._giface.WriteError(_("Failed to run d.to.rast:\n") + messages)
gs.try_remove(pngFile)
return
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/nviz/mapwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def OnKeyDown(self, event):
Used for fly-through mode.
"""
if not self.mouse["use"] == "fly":
if self.mouse["use"] != "fly":
return

key = event.GetKeyCode()
Expand Down Expand Up @@ -596,7 +596,7 @@ def OnKeyUp(self, event):
Used for fly-through mode.
"""
if not self.mouse["use"] == "fly":
if self.mouse["use"] != "fly":
return

key = event.GetKeyCode()
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/nviz/wxnviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def print_progress(value):
"""Redirect progress info"""
global progress
if progress:
if not progress.GetRange() == 100:
if progress.GetRange() != 100:
progress.SetRange(100)
progress.SetValue(value)
else:
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/photo2image/ip2i_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ def AdjustMap(self, newreg):
def OnZoomToSource(self, event):
"""Set target map window to match extents of source map window"""

if not self.MapWindow == self.TgtMapWindow:
if self.MapWindow != self.TgtMapWindow:
self.MapWindow = self.TgtMapWindow
self.Map = self.TgtMap
self.UpdateActive(self.TgtMapWindow)
Expand All @@ -1544,7 +1544,7 @@ def OnZoomToSource(self, event):
def OnZoomToTarget(self, event):
"""Set source map window to match extents of target map window"""

if not self.MapWindow == self.SrcMapWindow:
if self.MapWindow != self.SrcMapWindow:
self.MapWindow = self.SrcMapWindow
self.Map = self.SrcMap
self.UpdateActive(self.SrcMapWindow)
Expand Down Expand Up @@ -2381,7 +2381,7 @@ def OnSrcSelection(self, event):

tmp_map = self.srcselection.GetValue()

if not tmp_map == "" and not tmp_map == src_map:
if tmp_map not in ("", src_map):
self.new_src_map = tmp_map

def OnTgtRastSelection(self, event):
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/photo2image/ip2i_mapdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def GetMapToolbar(self):
return self.toolbars["gcpdisp"]

def _setActiveMapWindow(self, mapWindow):
if not self.MapWindow == mapWindow:
if self.MapWindow != mapWindow:
self.MapWindow = mapWindow
self.Map = mapWindow.Map
self.UpdateActive(mapWindow)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/psmap/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def OnPsMapDialog(self, event):

def OnPDFFile(self, event):
"""Generate PDF from PS with ps2pdf if available"""
if not sys.platform == "win32":
if sys.platform != "win32":
try:
p = gs.Popen(["ps2pdf"], stderr=gs.PIPE)
p.stderr.close()
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/rdigit/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def OnOK(self, event):
caption=_("Overwrite?"),
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
)
if not dlgOverwrite.ShowModal() == wx.ID_YES:
if dlgOverwrite.ShowModal() != wx.ID_YES:
dlgOverwrite.Destroy()
return
else:
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/vdigit/wxdigit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ def EditLine(self, line, coords):
# apply snapping (node or vertex)
snap = self._getSnapMode()
if snap != NO_SNAP:
modeSnap = not (snap == SNAP)
modeSnap = snap != SNAP
Vedit_snap_line(
self.poMapInfo,
self.popoBgMapInfo,
Expand Down Expand Up @@ -1889,7 +1889,7 @@ def _addFeature(self, ftype, coords, layer, cat, snap, threshold):

if snap != NO_SNAP:
# apply snapping (node or vertex)
modeSnap = not (snap == SNAP)
modeSnap = snap != SNAP
Vedit_snap_line(
self.poMapInfo,
self.popoBgMapInfo,
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/vnet/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def IsShown(self, colName) -> bool:
:return: False - if is not shown
"""

return not self._getColumnNum(colName) == -1
return self._getColumnNum(colName) != -1


class EditItem(wx.Dialog):
Expand Down
4 changes: 2 additions & 2 deletions lib/init/grass.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def create_grass_config_dir():
os.makedirs(directory)
except OSError as e:
# Can happen as a race condition
if not e.errno == errno.EEXIST or not os.path.isdir(directory):
if e.errno != errno.EEXIST or not os.path.isdir(directory):
fatal(
_(
"Failed to create configuration directory '{}' with error: {}"
Expand Down Expand Up @@ -1631,7 +1631,7 @@ def sh_like_startup(location, location_name, grass_env_file, sh):

# save command history in mapset dir and remember more
# bash history file handled in specific_addition
if not sh == "bash":
if sh != "bash":
os.environ["HISTFILE"] = os.path.join(location, sh_history)

# instead of changing $HOME, start bash with:
Expand Down
2 changes: 1 addition & 1 deletion man/build_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def get_module_man_html_file_path(module):
for k in sorted(char_list.keys()):
test_length += 1
# toc += '<li><a href="#%s" class="toc">%s</a></li>' % (char_list[k], k)
if test_length % 4 == 0 and not test_length == all_keys:
if test_length % 4 == 0 and test_length != all_keys:
toc += '\n<a href="#%s" class="toc">%s</a>, ' % (char_list[k], k)
elif test_length % 4 == 0 and test_length == all_keys:
toc += '\n<a href="#%s" class="toc">%s</a>' % (char_list[k], k)
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ ignore = [
"SIM114", # if-with-same-arms
"SIM116", # if-else-block-instead-of-dict-lookup
"SIM118", # in-dict-keys
"SIM201", # negate-equal-op
"SIM223", # expr-and-false
"SIM401", # if-else-block-instead-of-dict-get
"SLF001", # private-member-access
Expand Down
2 changes: 1 addition & 1 deletion python/grass/gunittest/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def assertFileMd5(self, filename, md5, text=False, msg=None):
actual = text_file_md5(filename)
else:
actual = file_md5(filename)
if not actual == md5:
if actual != md5:
standardMsg = (
"File <{name}> does not have the right MD5 sum.\n"
"Expected is <{expected}>,"
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/modules/interface/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def __init__(self, xparameter=None, diz=None):
#
if "gisprompt" in diz and diz["gisprompt"]:
self.typedesc = diz["gisprompt"].get("prompt", "")
self.input = not diz["gisprompt"]["age"] == "new"
self.input = diz["gisprompt"]["age"] != "new"
else:
self.input = True

Expand Down
4 changes: 2 additions & 2 deletions python/grass/temporal/spatial_extent.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ def cover_2d(self, extent) -> bool:
if eS > S and eS < N:
edge_count += 1

return not edge_count == 0
return edge_count != 0

def cover(self, extent) -> bool:
"""Return True if this extent covers the provided spatial
Expand Down Expand Up @@ -956,7 +956,7 @@ def cover(self, extent) -> bool:
if eB > B and eB < T:
edge_count += 1

return not edge_count == 0
return edge_count != 0

def covered_2d(self, extent):
"""Return True if this extent is covered by the provided spatial
Expand Down
2 changes: 1 addition & 1 deletion scripts/g.extension.all/g.extension.all.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def download_modules_xml_file(url, response_format, *args, **kwargs):
try:
response = urlopen(url, *args, **kwargs)

if not response.code == 200:
if response.code != 200:
index = HTTP_STATUS_CODES.index(response.code)
desc = HTTP_STATUS_CODES[index].description
gs.fatal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def read_semantic_label(self):
return rast.info.semantic_label

def test_semantic_label_assign_not_current_mapset(self):
if not self.mapset == "PERMANENT":
if self.mapset != "PERMANENT":
self.mapset.name = "PERMANENT"
a_map = self.mapset.glist(type="raster")[0]
module = SimpleModule(
Expand Down
Loading

0 comments on commit 49f67fd

Please sign in to comment.