Skip to content

Commit

Permalink
style: Fix repeated-equality-comparison (PLR1714) (#4042)
Browse files Browse the repository at this point in the history
* style: Fix repeated-equality-comparison (PLR1714)
* style: Fix literal-membership (PLR6201)
  • Loading branch information
echoix authored Jul 13, 2024
1 parent a751f93 commit 3b309db
Show file tree
Hide file tree
Showing 42 changed files with 85 additions and 107 deletions.
4 changes: 2 additions & 2 deletions gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def ListOfMapsets(get="ordered"):
:return: list of mapsets
:return: [] on error
"""
if get == "all" or get == "ordered":
if get in {"all", "ordered"}:
ret = RunCommand("g.mapsets", read=True, quiet=True, flags="l", sep="newline")
if not ret:
return []
Expand All @@ -297,7 +297,7 @@ def ListOfMapsets(get="ordered"):
if get == "all":
return mapsets_all

if get == "accessible" or get == "ordered":
if get in {"accessible", "ordered"}:
ret = RunCommand("g.mapsets", read=True, quiet=True, flags="p", sep="newline")
if not ret:
return []
Expand Down
12 changes: 3 additions & 9 deletions gui/wxpython/core/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def __init__(self, patterns, element, event_handler):
self.event_handler = event_handler

def on_created(self, event):
if (
self.element == "vector" or self.element == "raster_3d"
) and not event.is_directory:
if (self.element in {"vector", "raster_3d"}) and not event.is_directory:
return
evt = updateMapset(
src_path=event.src_path,
Expand All @@ -107,9 +105,7 @@ def on_created(self, event):
wx.PostEvent(self.event_handler, evt)

def on_deleted(self, event):
if (
self.element == "vector" or self.element == "raster_3d"
) and not event.is_directory:
if (self.element in {"vector", "raster_3d"}) and not event.is_directory:
return
evt = updateMapset(
src_path=event.src_path,
Expand All @@ -120,9 +116,7 @@ def on_deleted(self, event):
wx.PostEvent(self.event_handler, evt)

def on_moved(self, event):
if (
self.element == "vector" or self.element == "raster_3d"
) and not event.is_directory:
if (self.element in {"vector", "raster_3d"}) and not event.is_directory:
return
evt = updateMapset(
src_path=event.src_path,
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gui_core/ghelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ def _langPanel(self, lang, js):
# panel.Collapse(True)
pageSizer = wx.BoxSizer(wx.VERTICAL)
for k, v in js.items():
if k != "total" and k != "name":
if k not in {"total", "name"}:
box = self._langBox(win, k, v)
pageSizer.Add(box, proportion=1, flag=wx.EXPAND | wx.ALL, border=3)

Expand Down
6 changes: 2 additions & 4 deletions gui/wxpython/history/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,10 @@ def _createRegionSettingsBox(self):

def _general_info_filter(self, key, value):
filter_keys = ["timestamp", "runtime", "status"]
return key in filter_keys or (
(key == "mask2d" or key == "mask3d") and value is True
)
return key in filter_keys or ((key in {"mask2d", "mask3d"}) and value is True)

def _region_settings_filter(self, key):
return (key != "projection") and (key != "zone") and (key != "cells")
return key not in {"projection", "zone", "cells"}

def _updateGeneralInfoBox(self, command_info):
"""Update a static box for displaying general info about the command.
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/lmgr/statusbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def dbChanged(self, map=None, newname=None):
:param str map: map that is changed
:param str newname: new map
"""
if map == self.mask_layer or newname == self.mask_layer:
if self.mask_layer in {map, newname}:
self.Refresh()
self.giface.updateMap.emit()

Expand Down
10 changes: 5 additions & 5 deletions gui/wxpython/main_window/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,11 +1058,11 @@ def _closePageNoEvent(self, pgnum_dict, is_docked):

def _focusPage(self, notification):
"""Focus the 'Console' notebook page according to event notification."""
if (
notification == Notification.HIGHLIGHT
or notification == Notification.MAKE_VISIBLE
or notification == Notification.RAISE_WINDOW
):
if notification in {
Notification.HIGHLIGHT,
Notification.MAKE_VISIBLE,
Notification.RAISE_WINDOW,
}:
self.FocusPage("Console")

def FocusPage(self, page_text):
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/nviz/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2642,7 +2642,7 @@ def GetLayerData(self, nvizType, nameOnly=False):
if nameOnly:
return name

if nvizType == "surface" or nvizType == "fringe":
if nvizType in {"surface", "fringe"}:
return self._getLayerPropertiesByName(name, mapType="raster")
elif nvizType == "vector":
return self._getLayerPropertiesByName(name, mapType="vector")
Expand Down Expand Up @@ -4044,7 +4044,7 @@ def UpdateVectorShow(self, vecType, enabled):
:param vecType: vector type (lines, points)
"""
if vecType != "lines" and vecType != "points":
if vecType not in {"lines", "points"}:
return False

for win in self.win["vector"][vecType].keys():
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 @@ -570,7 +570,7 @@ def getFile(self, wildcard):
suffix = suffix[dlg.GetFilterIndex()]
if not os.path.splitext(filename)[1]:
filename = filename + suffix
elif os.path.splitext(filename)[1] != suffix and suffix != "":
elif suffix not in {os.path.splitext(filename)[1], ""}:
filename = os.path.splitext(filename)[0] + suffix

dlg.Destroy()
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/rlisetup/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def _write_area(self, fil):
fil.write("\nMOVINGWINDOW\n")
# KUNITSC = samplingtype=units, regionbox=keyboard, shape=cirlce
# KUNITSR = samplingtype=units, regionbox=keyboard, shape=rectangle
elif samtype == SamplingType.KUNITSC or samtype == SamplingType.KUNITSR:
elif samtype in {SamplingType.KUNITSC, SamplingType.KUNITSR}:
if samtype == SamplingType.KUNITSC:
self._circle(self.units.width, self.units.height)
cl = float(self.CIR_CL) / float(self.rasterinfo["cols"])
Expand Down Expand Up @@ -1115,7 +1115,7 @@ def ShowExtraOptions(self, samtype):
self.sizer.Hide(self.areaPanel)
self.sizer.Hide(self.calculatingAreas)
self.sizer.Show(self.regionNumPanel)
elif samtype == SamplingType.UNITS or samtype == SamplingType.MVWIN:
elif samtype in {SamplingType.UNITS, SamplingType.MVWIN}:
self.sizer.Hide(self.regionNumPanel)
self.sizer.Hide(self.areaPanel)
self.sizer.Hide(self.calculatingAreas)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/tools/build_modules_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def parse_modules(fd):
indent = 4
for m in sorted(mlist):
# TODO: get rid of g.mapsets_picker.py
if m == "g.mapsets_picker.py" or m == "g.parser":
if m in {"g.mapsets_picker.py", "g.parser"}:
continue
desc, keyw = get_module_metadata(m)
fd.write('%s<module-item name="%s">\n' % (" " * indent, m))
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/web_services/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def OnCmdOutput(self, event):
"""Manage cmd output."""
if Debug.GetLevel() != 0:
Debug.msg(1, event.text)
elif event.type != "message" and event.type != "warning":
elif event.type not in {"message", "warning"}:
self.cmd_err_str += event.text + os.linesep

def _prepareForNewConn(self, url, username, password):
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/wxplot/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ def PlotText(self, event):
)

btnval = dlg.ShowModal()
if btnval == wx.ID_SAVE or btnval == wx.ID_OK or btnval == wx.ID_CANCEL:
if btnval in {wx.ID_SAVE, wx.ID_OK, wx.ID_CANCEL}:
dlg.Destroy()

def PlotOptions(self, event):
Expand All @@ -602,7 +602,7 @@ def PlotOptions(self, event):
)
btnval = dlg.ShowModal()

if btnval == wx.ID_SAVE or btnval == wx.ID_OK or btnval == wx.ID_CANCEL:
if btnval in {wx.ID_SAVE, wx.ID_OK, wx.ID_CANCEL}:
dlg.Destroy()
self.Update()

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ ignore = [
"PLR0917", # too-many-positional
"PLR1702", # too-many-nested-blocks
"PLR1704", # redefined-argument-from-local
"PLR1714", # repeated-equality-comparison
"PLR1733", # unnecessary-dict-index-lookup
"PLR2004", # magic-value-comparison
"PLR5501", # collapsible-else-if
Expand Down
4 changes: 2 additions & 2 deletions python/grass/gunittest/gutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def is_map_in_mapset(name, type, mapset=None):
# so anything accepted by g.findfile will work but this can change in the
# future (the documentation is clear about what's legal)
# supporting both short and full names
if type == "rast" or type == "raster":
if type in {"rast", "raster"}:
type = "cell"
elif type == "rast3d" or type == "raster3d":
elif type in {"rast3d", "raster3d"}:
type = "grid3"
elif type == "vect":
type = "vector"
Expand Down
6 changes: 3 additions & 3 deletions python/grass/pygrass/raster/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,12 @@ def open(self, mode=None, mtype=None, overwrite=None):
self.cats.mtype = self.mtype
self.cats.read()
self.hist.read()
if (self.mode == "w" or self.mode == "rw") and self.overwrite is False:
if (self.mode in {"w", "rw"}) and self.overwrite is False:
str_err = _("Raster map <{0}> already exists. Use overwrite.")
fatal(str_err.format(self))

# We copy the raster map content into the segments
if self.mode == "rw" or self.mode == "r":
if self.mode in {"rw", "r"}:
self._fd = libraster.Rast_open_old(self.name, self.mapset)
self._gtype = libraster.Rast_get_map_type(self._fd)
self.mtype = RTYPE_STR[self._gtype]
Expand Down Expand Up @@ -563,7 +563,7 @@ def close(self, rm_temp_files=True):
:param rm_temp_files: if True all the segments file will be removed
:type rm_temp_files: bool
"""
if self.mode == "w" or self.mode == "rw":
if self.mode in {"w", "rw"}:
self.segment.flush()
self.segment2map()
if rm_temp_files:
Expand Down
9 changes: 3 additions & 6 deletions python/grass/pygrass/vector/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@

def is_open(c_mapinfo):
"""Return if the Vector is open"""
return (
c_mapinfo.contents.open != 0
and c_mapinfo.contents.open != libvect.VECT_CLOSED_CODE
)
return c_mapinfo.contents.open not in {0, libvect.VECT_CLOSED_CODE}


# =============================================
Expand Down Expand Up @@ -465,8 +462,8 @@ def close(self, build=False):
str_err = "Error when trying to close the map with Vect_close"
raise GrassError(str_err)
if (
self.c_mapinfo.contents.mode == libvect.GV_MODE_RW
or self.c_mapinfo.contents.mode == libvect.GV_MODE_WRITE
self.c_mapinfo.contents.mode
in {libvect.GV_MODE_RW, libvect.GV_MODE_WRITE}
) and build:
self.build()

Expand Down
2 changes: 1 addition & 1 deletion python/grass/script/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def write(self, mapname, null=None, overwrite=None, quiet=None):
flags = None

if kind == "f":
if size != 4 and size != 8:
if size not in {4, 8}:
raise ValueError(_("Invalid FP size <%d>") % size)
elif kind in "biu":
if size not in {1, 2, 4, 8}:
Expand Down
4 changes: 2 additions & 2 deletions python/grass/script/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def separator(sep):
return ","
elif sep == "space":
return " "
elif sep == "tab" or sep == "\\t":
elif sep in {"tab", "\\t"}:
return "\t"
elif sep == "newline" or sep == "\\n":
elif sep in {"newline", "\\n"}:
return "\n"
return sep

Expand Down
6 changes: 3 additions & 3 deletions python/grass/temporal/abstract_space_time_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def check_temporal_topology(self, maps=None, dbif=None):

map_time = self.get_map_time()

if map_time == "interval" or map_time == "mixed":
if map_time in {"interval", "mixed"}:
if "equal" in relations and relations["equal"] > 0:
return False
if "during" in relations and relations["during"] > 0:
Expand Down Expand Up @@ -966,9 +966,9 @@ def sample_by_dataset_sql(self, stds, method=None, spatial=False, dbif=None):
use_during = True
if name == "overlap":
use_overlap = True
if name == "contain" or name == "contains":
if name in {"contain", "contains"}:
use_contain = True
if name == "equal" or name == "equals":
if name in {"equal", "equals"}:
use_equal = True
if name == "follows":
use_follows = True
Expand Down
2 changes: 1 addition & 1 deletion python/grass/temporal/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def set_ttype(self, ttype):
:param ttype: The temporal type of the dataset "absolute or relative"
"""
if ttype is None or (ttype != "absolute" and ttype != "relative"):
if ttype is None or (ttype not in {"absolute", "relative"}):
self.D["temporal_type"] = "absolute"
else:
self.D["temporal_type"] = ttype
Expand Down
2 changes: 1 addition & 1 deletion python/grass/temporal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def profile_function(func):
"""Profiling function provided by the temporal framework"""
do_profiling = os.getenv("GRASS_TGIS_PROFILE")

if do_profiling == "True" or do_profiling == "1":
if do_profiling in {"True", "1"}:
import cProfile
import io
import pstats
Expand Down
2 changes: 1 addition & 1 deletion python/grass/temporal/datetime_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def modify_datetime_by_string(mydate, increment, mult=1, sign=1):
:return: The new datetime object or none in case of an error
"""
sign = int(sign)
if sign != 1 and sign != -1:
if sign not in {1, -1}:
return None

if increment:
Expand Down
2 changes: 1 addition & 1 deletion python/grass/temporal/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def extract_dataset(

# In case of a empty map continue, do not register empty
# maps
if type == "raster" or type == "raster3d":
if type in {"raster", "raster3d"}:
if (
new_map.metadata.get_min() is None
and new_map.metadata.get_max() is None
Expand Down
6 changes: 3 additions & 3 deletions python/grass/temporal/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def dataset_factory(type, id):
sp = SpaceTimeRaster3DDataset(id)
elif type == "stvds":
sp = SpaceTimeVectorDataset(id)
elif type == "rast" or type == "raster":
elif type in {"rast", "raster"}:
sp = RasterDataset(id)
elif type == "raster_3d" or type == "rast3d" or type == "raster3d":
elif type in {"raster_3d", "rast3d", "raster3d"}:
sp = Raster3DDataset(id)
elif type == "vect" or type == "vector":
elif type in {"vect", "vector"}:
sp = VectorDataset(id)
else:
msgr = get_tgis_message_interface()
Expand Down
2 changes: 1 addition & 1 deletion python/grass/temporal/mapcalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def dataset_mapcalculator(
proc_list[proc_count].start()
proc_count += 1

if proc_count == nprocs or proc_count == num or count == num:
if proc_count in {nprocs, num} or count == num:
proc_count = 0
exitcodes = 0
for proc in proc_list:
Expand Down
22 changes: 6 additions & 16 deletions python/grass/temporal/open_stds.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,13 @@ def open_old_stds(name, type, dbif=None):
msgr.fatal("Invalid name of the space time dataset. Only one dot allowed.")
id = name + "@" + mapset

if type == "strds" or type == "rast" or type == "raster":
if type in {"strds", "rast", "raster"}:
sp = dataset_factory("strds", id)
if semantic_label:
sp.set_semantic_label(semantic_label)
elif (
type == "str3ds"
or type == "raster3d"
or type == "rast3d"
or type == "raster_3d"
):
elif type in {"str3ds", "raster3d", "rast3d", "raster_3d"}:
sp = dataset_factory("str3ds", id)
elif type == "stvds" or type == "vect" or type == "vector":
elif type in {"stvds", "vect", "vector"}:
sp = dataset_factory("stvds", id)
else:
msgr.fatal(_("Unknown type: %s") % (type))
Expand Down Expand Up @@ -123,21 +118,16 @@ def check_new_stds(name, type, dbif=None, overwrite=False):
)
id = name

if type == "strds" or type == "rast" or type == "raster":
if type in {"strds", "rast", "raster"}:
if name.find(".") > -1:
# a dot is used as a separator for semantic label filtering
msgr.fatal(
_("Illegal dataset name <{}>. Character '.' not allowed.").format(name)
)
sp = dataset_factory("strds", id)
elif (
type == "str3ds"
or type == "raster3d"
or type == "rast3d "
or type == "raster_3d"
):
elif type in {"str3ds", "raster3d", "rast3d ", "raster_3d"}:
sp = dataset_factory("str3ds", id)
elif type == "stvds" or type == "vect" or type == "vector":
elif type in {"stvds", "vect", "vector"}:
sp = dataset_factory("stvds", id)
else:
msgr.error(_("Unknown type: %s") % (type))
Expand Down
Loading

0 comments on commit 3b309db

Please sign in to comment.