Skip to content

Commit

Permalink
style(gui): Fixes literal-membership (PLR6201) (OSGeo#3952)
Browse files Browse the repository at this point in the history
* style(gui/wxpython): Fixes literal-membership (PLR6201)

Concerns Pylint rule "use-set-for-membership / R6201"

Using `ruff check --output-format=concise --select PLR6201 --preview --unsafe-fixes --fix gui/`.

* style: Apply single element in set formatting
  • Loading branch information
echoix authored and cyliang368 committed Jul 1, 2024
1 parent a056499 commit 665a321
Show file tree
Hide file tree
Showing 59 changed files with 330 additions and 330 deletions.
4 changes: 2 additions & 2 deletions gui/wxpython/animation/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def EvaluateInput(self, animationData):
for anim in animationData:
for layer in anim.layerList:
if layer.active and hasattr(layer, "maps"):
if layer.mapType in ("strds", "stvds", "str3ds"):
if layer.mapType in {"strds", "stvds", "str3ds"}:
stds += 1
else:
maps += 1
Expand Down Expand Up @@ -672,5 +672,5 @@ def export_avi_callback(event):
del self.busy
GError(parent=self.frame, message=str(e))
return
if exportInfo["method"] in ("sequence", "gif", "swf"):
if exportInfo["method"] in {"sequence", "gif", "swf"}:
del self.busy
4 changes: 2 additions & 2 deletions gui/wxpython/animation/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def SetLayerList(self, layerList):
timeseriesList = []
for layer in layerList:
if layer.active and hasattr(layer, "maps"):
if layer.mapType in ("strds", "stvds", "str3ds"):
if layer.mapType in {"strds", "stvds", "str3ds"}:
timeseriesList.append((layer.name, layer.mapType))
self._firstStdsNameType = layer.name, layer.mapType
else:
Expand Down Expand Up @@ -298,7 +298,7 @@ def SetName(self, name):
raise ValueError(
"To set layer name, the type of layer must be specified."
)
if self._mapType in ("strds", "stvds", "str3ds"):
if self._mapType in {"strds", "stvds", "str3ds"}:
try:
name = validateTimeseriesName(name, self._mapType)
self._maps = getRegisteredMaps(name, self._mapType)
Expand Down
16 changes: 8 additions & 8 deletions gui/wxpython/animation/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ def OnSelectionChanged(self, event):
self._hideAll()
return
cdata = self.listbox.GetClientData(index)
self.hidevbox.Show(self.fontBox, (cdata["name"] in ("time", "text")))
self.hidevbox.Show(self.fontBox, (cdata["name"] in {"time", "text"}))
self.hidevbox.Show(self.imageBox, (cdata["name"] == "image"))
self.hidevbox.Show(self.textBox, (cdata["name"] == "text"))
self.hidevbox.Show(self.posBox, True)
Expand All @@ -1409,7 +1409,7 @@ def OnSelectionChanged(self, event):
self.spinY.SetValue(cdata["pos"][1])
if cdata["name"] == "image":
self.browse.SetValue(cdata["file"])
elif cdata["name"] in ("time", "text"):
elif cdata["name"] in {"time", "text"}:
self.sampleLabel.SetFont(cdata["font"])
if cdata["name"] == "text":
self.textCtrl.SetValue(cdata["text"])
Expand Down Expand Up @@ -1750,7 +1750,7 @@ def _setType(self, typeName=None):
if typeName:
self.tchoice.SetStringSelection(self._types[typeName])
self.tselect.SetType(typeName)
if typeName in ("strds", "stvds", "str3ds"):
if typeName in {"strds", "stvds", "str3ds"}:
self.tselect.SetType(typeName, multiple=False)
self.addManyMapsButton.Disable()
else:
Expand All @@ -1760,7 +1760,7 @@ def _setType(self, typeName=None):
self.tselect.SetValue("")
else:
typeName = self.tchoice.GetClientData(self.tchoice.GetSelection())
if typeName in ("strds", "stvds", "str3ds"):
if typeName in {"strds", "stvds", "str3ds"}:
self.tselect.SetType(typeName, multiple=False)
self.addManyMapsButton.Disable()
else:
Expand All @@ -1773,14 +1773,14 @@ def _setType(self, typeName=None):

def _createDefaultCommand(self):
cmd = []
if self._mapType in ("raster", "strds"):
if self._mapType in {"raster", "strds"}:
cmd.append("d.rast")
elif self._mapType in ("vector", "stvds"):
elif self._mapType in {"vector", "stvds"}:
cmd.append("d.vect")
elif self._mapType in ("raster_3d", "str3ds"):
elif self._mapType in {"raster_3d", "str3ds"}:
cmd.append("d.rast3d")
if self._name:
if self._mapType in ("raster", "vector", "raster_3d"):
if self._mapType in {"raster", "vector", "raster_3d"}:
cmd.append("map={name}".format(name=self._name.split(",")[0]))
else:
try:
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/core/gcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def send(self, input):
except ValueError:
return self._close("stdin")
except (pywintypes.error, Exception) as why:
if why.winerror in (109, errno.ESHUTDOWN):
if why.winerror in {109, errno.ESHUTDOWN}:
return self._close("stdin")
raise

Expand All @@ -244,7 +244,7 @@ def _recv(self, which, maxsize):
except ValueError:
return self._close(which)
except (pywintypes.error, Exception) as why:
if why.winerror in (109, errno.ESHUTDOWN):
if why.winerror in {109, errno.ESHUTDOWN}:
return self._close(which)
raise

Expand Down
8 changes: 4 additions & 4 deletions gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ def RunCmd(
return

skipInterface = True
if os.path.splitext(command[0])[1] in (".py", ".sh"):
if os.path.splitext(command[0])[1] in {".py", ".sh"}:
try:
with open(command[0], "r") as sfile:
for line in sfile.readlines():
Expand Down Expand Up @@ -805,14 +805,14 @@ def OnCmdDone(self, event):
name = task.get_name()
for p in task.get_options()["params"]:
prompt = p.get("prompt", "")
if prompt in ("raster", "vector", "raster_3d") and p.get("value", None):
if p.get("age", "old") == "new" or name in (
if prompt in {"raster", "vector", "raster_3d"} and p.get("value", None):
if p.get("age", "old") == "new" or name in {
"r.colors",
"r3.colors",
"v.colors",
"v.proj",
"r.proj",
):
}:
# if multiple maps (e.g. r.series.interp), we need add each
if p.get("multiple", False):
lnames = p.get("value").split(",")
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/core/globalvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def CheckForWx():
# use UBUNTU_MENUPROXY=0 to disable global menu on ubuntu but in the same time
# to get smaller lmgr
# [1] https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationMenu#Troubleshooting
if sys.platform in ("win32", "darwin") or os.environ.get("UBUNTU_MENUPROXY"):
if sys.platform in {"win32", "darwin"} or os.environ.get("UBUNTU_MENUPROXY"):
GM_WINDOW_SIZE = (GM_WINDOW_MIN_SIZE[0], 600)
else:
GM_WINDOW_SIZE = (625, 600)
Expand Down Expand Up @@ -213,12 +213,12 @@ def UpdateGRASSAddOnCommands(eList=None):
os.environ["PATH"] = path + os.pathsep + os.environ["PATH"]

for fname in os.listdir(path):
if fname in ["docs", "modules.xml"]:
if fname in {"docs", "modules.xml"}:
continue
if grassScripts: # win32
name, ext = os.path.splitext(fname)
if name not in grassCmd:
if ext not in [BIN_EXT, SCT_EXT]:
if ext not in {BIN_EXT, SCT_EXT}:
continue
if name not in grassCmd:
grassCmd.add(name)
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/core/menutree.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ def collectParents(node, parents):
menu = "manager"

for arg in sys.argv:
if arg in ("strings", "tree", "commands", "dump"):
if arg in {"strings", "tree", "commands", "dump"}:
action = arg
elif arg in ("manager", "module_tree", "modeler", "psmap"):
elif arg in {"manager", "module_tree", "modeler", "psmap"}:
menu = arg

# FIXME: cross-dependencies
Expand Down
10 changes: 5 additions & 5 deletions gui/wxpython/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class MapLayer(Layer):
def __init__(self, *args, **kwargs):
"""Represents map layer in the map canvas"""
Layer.__init__(self, *args, **kwargs)
if self.type in ("vector", "thememap"):
if self.type in {"vector", "thememap"}:
self._legrow = get_tempfile_name(suffix=".legrow", create=True)
else:
self._legrow = ""
Expand Down Expand Up @@ -439,7 +439,7 @@ def Render(self, cmd, env):
env_cmd = env.copy()
env_cmd.update(self._render_env)
env_cmd["GRASS_RENDER_FILE"] = self.layer.mapfile
if self.layer.GetType() in ("vector", "thememap"):
if self.layer.GetType() in {"vector", "thememap"}:
if not self.layer._legrow:
self.layer._legrow = grass.tempfile(create=True)
if os.path.isfile(self.layer._legrow):
Expand Down Expand Up @@ -721,7 +721,7 @@ def OnRenderDone(self, env):
new_legend = []
with open(self.Map.legfile, "w") as outfile:
for layer in reversed(self.layers):
if layer.GetType() not in ("vector", "thememap"):
if layer.GetType() not in {"vector", "thememap"}:
continue

if os.path.isfile(layer._legrow) and not layer.hidden:
Expand Down Expand Up @@ -883,7 +883,7 @@ def _projInfo(self):
for line in ret.splitlines():
if ":" in line:
key, val = map(lambda x: x.strip(), line.split(":", 1))
if key in ["units"]:
if key in {"units"}:
val = val.lower()
projinfo[key] = val
elif "XY location (unprojected)" in line:
Expand Down Expand Up @@ -1452,7 +1452,7 @@ def DeleteLayer(self, layer, overlay=False):
for f in glob.glob(basefile):
os.remove(f)

if layer.GetType() in ("vector", "thememap"):
if layer.GetType() in {"vector", "thememap"}:
if os.path.isfile(layer._legrow):
os.remove(layer._legrow)

Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def colorhex2tuple(hexcode):
return tuple(int(hexcode[i : i + 2], 16) for i in range(0, len(hexcode), 2))

for k, v in obj.items():
if isinstance(v, str) and v.startswith("#") and len(v) in [7, 9]:
if isinstance(v, str) and v.startswith("#") and len(v) in {7, 9}:
obj[k] = colorhex2tuple(v)
return obj

Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/treemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def match(self, key, value, case_sensitive=False):
keys = key

for key in keys:
if key not in ("command", "keywords", "description"):
if key not in {"command", "keywords", "description"}:
return False
try:
text = self.data[key]
Expand Down
24 changes: 12 additions & 12 deletions gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def GetLayerNameFromCmd(dcmd, fullyQualified=False, param=None, layerType=None):
break

# this does not use types, just some (incomplete subset of?) names
if p in (
if p in {
"map",
"input",
"layer",
Expand All @@ -133,7 +133,7 @@ def GetLayerNameFromCmd(dcmd, fullyQualified=False, param=None, layerType=None):
"intensity",
"shade",
"labels",
):
}:
params.append((idx, p, v))

if len(params) < 1:
Expand Down Expand Up @@ -161,9 +161,9 @@ def GetLayerNameFromCmd(dcmd, fullyQualified=False, param=None, layerType=None):
mapname = v
mapset = ""
if fullyQualified and "@" not in mapname:
if layerType in ("raster", "vector", "raster_3d", "rgb", "his"):
if layerType in {"raster", "vector", "raster_3d", "rgb", "his"}:
try:
if layerType in ("raster", "rgb", "his"):
if layerType in {"raster", "rgb", "his"}:
findType = "cell"
elif layerType == "raster_3d":
findType = "grid3"
Expand Down Expand Up @@ -477,11 +477,11 @@ def __ll_parts(value, reverse=False, precision=3):
except ValueError:
raise ValueError

if hs not in ("N", "S", "E", "W"):
if hs not in {"N", "S", "E", "W"}:
raise ValueError

coef = 1.0
if hs in ("S", "W"):
if hs in {"S", "W"}:
coef = -1.0

fm = int(m) / 60.0
Expand Down Expand Up @@ -552,7 +552,7 @@ def ReprojectCoordinates(coord, projOut, projIn=None, flags=""):
proj = projOut.split(" ")[0].split("=")[1]
except IndexError:
proj = ""
if proj in ("ll", "latlong", "longlat") and "d" not in flags:
if proj in {"ll", "latlong", "longlat"} and "d" not in flags:
return (proj, (e, n))
else:
try:
Expand Down Expand Up @@ -666,9 +666,9 @@ def _parseFormats(output, writableOnly=False):
if writableOnly and not patt.search(key):
continue

if name in ("Memory", "Virtual Raster", "In Memory Raster"):
if name in {"Memory", "Virtual Raster", "In Memory Raster"}:
continue
if name in (
if name in {
"PostgreSQL",
"PostgreSQL/PostGIS",
"SQLite",
Expand All @@ -681,16 +681,16 @@ def _parseFormats(output, writableOnly=False):
"CouchDB",
"MSSQLSpatial",
"FileGDB",
):
}:
formats["database"][key.split(" ")[0]] = name
elif name in (
elif name in {
"GeoJSON",
"OGC Web Coverage Service",
"OGC Web Map Service",
"WFS",
"GeoRSS",
"HTTP Fetching Wrapper",
):
}:
formats["protocol"][key.split(" ")[0]] = name
else:
formats["file"][key.split(" ")[0]] = name
Expand Down
Loading

0 comments on commit 665a321

Please sign in to comment.