Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Fix if-expr-with-true-false (SIM210) and if-expr-with-false-true (SIM211) #3999

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gui/wxpython/core/globalvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def UpdateGRASSAddOnCommands(eList=None):
hasAgw = CheckWxVersion([2, 8, 11, 0])
wxPythonPhoenix = CheckWxPhoenix()

gtk3 = True if "gtk3" in wx.PlatformInfo else False
gtk3 = "gtk3" in wx.PlatformInfo

"""@Add GUIDIR/scripts into path"""
os.environ["PATH"] = os.path.join(GUIDIR, "scripts") + os.pathsep + os.environ["PATH"]
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gmodeler/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def OnLeftClick(self, x, y, keys=0, attachment=0):
del self.frame.defineRelation

# select object
self._onSelectShape(shape, append=True if keys == 1 else False)
self._onSelectShape(shape, append=keys == 1)

if hasattr(shape, "GetLog"):
self.log.SetStatusText(shape.GetLog(), 0)
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/gmodeler/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2166,9 +2166,9 @@ def _processData(self):
prompt = param.get("prompt", None)
value = self._filterValue(self._getNodeText(param, "value"))

intermediate = False if data.find("intermediate") is None else True
intermediate = not data.find("intermediate") is None

display = False if data.find("display") is None else True
display = not data.find("display") is None

rels = []
for rel in data.findall("relation"):
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/lmgr/layertree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ def AddLayer(
# use predefined value if given
if lchecked is not None:
checked = lchecked
render = True if checked else False
render = bool(checked)
else:
checked = False
render = False
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ ignore = [
"SIM117", # multiple-with-statements
"SIM118", # in-dict-keys
"SIM201", # negate-equal-op
"SIM210", # if-expr-with-true-false
"SIM211", # if-expr-with-false-true
"SIM223", # expr-and-false
"SIM300", # yoda-conditions
"SIM401", # if-else-block-instead-of-dict-get
Expand Down
4 changes: 2 additions & 2 deletions python/grass/pygrass/modules/grid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def rmloc(r):

src = read_gisrc(gisrc_src)
dst = read_gisrc(gisrc_dst)
rm = True if src[2] != dst[2] else False
rm = src[2] != dst[2]
all_rasts = [r[0] for r in findmaps("raster", location=dst[1], gisdbase=dst[2])]
for grp in groups:
# change gisdbase to src
Expand Down Expand Up @@ -376,7 +376,7 @@ def cmd_exe(args):
src, dst = get_mapset(gisrc_src, gisrc_dst)
env = os.environ.copy()
env["GISRC"] = gisrc_dst
shell = True if sys.platform == "win32" else False
shell = sys.platform == "win32"
if mapnames:
inputs = dict(cmd["inputs"])
# reset the inputs to
Expand Down
6 changes: 2 additions & 4 deletions python/grass/pygrass/modules/interface/flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ def __init__(self, xflag=None, diz=None):
self.value = False
diz = read.element2dict(xflag) if xflag is not None else diz
self.name = diz["name"]
self.special = (
True if self.name in {"verbose", "overwrite", "quiet", "run"} else False
)
self.special = self.name in {"verbose", "overwrite", "quiet", "run"}
self.description = diz.get("description", None)
self.default = diz.get("default", None)
self.guisection = diz.get("guisection", None)
self.suppress_required = True if "suppress_required" in diz else False
self.suppress_required = "suppress_required" in diz

def get_bash(self):
"""Return the BASH representation of a flag.
Expand Down
6 changes: 3 additions & 3 deletions python/grass/pygrass/modules/interface/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ def __init__(self, xparameter=None, diz=None):
if diz is None:
raise TypeError("Xparameter or diz are required")
self.name = diz["name"]
self.required = True if diz["required"] == "yes" else False
self.multiple = True if diz["multiple"] == "yes" else False
self.required = diz["required"] == "yes"
self.multiple = diz["multiple"] == "yes"
# check the type
if diz["type"] in GETTYPE:
self.type = GETTYPE[diz["type"]]
Expand Down 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 = False if diz["gisprompt"]["age"] == "new" else True
self.input = not diz["gisprompt"]["age"] == "new"
else:
self.input = True

Expand Down
4 changes: 2 additions & 2 deletions python/grass/pygrass/modules/interface/testsuite/test_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def test_bool(self):
"""Test magic __bool__ method"""
flag = Flag(diz={"name": "a"})
flag.value = True
self.assertTrue(True if flag else False)
self.assertTrue(bool(flag))
flag.value = False
self.assertFalse(True if flag else False)
self.assertFalse(bool(flag))


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions python/grass/pygrass/raster/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def exist(self):
if self.mapset == "":
mapset = utils.get_mapset_raster(self.name, self.mapset)
self.mapset = mapset if mapset else ""
return True if mapset else False
return bool(mapset)
return bool(utils.get_mapset_raster(self.name, self.mapset))
else:
return False
Expand All @@ -445,7 +445,7 @@ def is_open(self):
False

"""
return True if self._fd is not None and self._fd >= 0 else False
return bool(self._fd is not None and self._fd >= 0)

@must_be_open
def close(self):
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def table_exist(cursor, table_name):
except OperationalError:
return False
one = cursor.fetchone() if cursor else None
return True if one and one[0] else False
return bool(one and one[0])


def create_test_vector_map(map_name="test_vector"):
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/vector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def has_color_table(self):
"""
loc = Location()
path = join(loc.path(), self.mapset, "vector", self.name, "colr")
return True if exists(path) else False
return bool(exists(path))


# =============================================
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/vector/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def exist(self):
if self.mapset == "":
mapset = utils.get_mapset_vector(self.name, self.mapset)
self.mapset = mapset if mapset else ""
return True if mapset else False
return bool(mapset)
return bool(utils.get_mapset_vector(self.name, self.mapset))
else:
return False
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/vector/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def __init__(self, x=0, y=0, z=None, **kargs):
if self.id and self.c_mapinfo:
self.read()
else:
self.is2D = True if z is None else False
self.is2D = z is None
z = z if z is not None else 0
libvect.Vect_append_point(self.c_points, x, y, z)

Expand Down
2 changes: 1 addition & 1 deletion utils/mkhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ def to_title(name):
git_commit = get_last_git_commit(
src_dir=curdir,
addon_path=addon_path if addon_path else None,
is_addon=True if addon_path else False,
is_addon=bool(addon_path),
)
if git_commit["commit"] == "unknown":
date_tag = "Accessed: {date}".format(date=git_commit["date"])
Expand Down
Loading