Skip to content

Commit 7e49a2b

Browse files
authored
style: Fix R1716: Simplify chained comparison between the operands (chained-comparison) (OSGeo#4902)
* style: Fix R1716: Simplify chained comparison between the operands (chained-comparison) Pylint rule: https://pylint.readthedocs.io/en/stable/user_guide/messages/refactor/chained-comparison.html * gui: Fix remaining Pylint R1716 issues
1 parent 4538f7d commit 7e49a2b

File tree

17 files changed

+31
-36
lines changed

17 files changed

+31
-36
lines changed

display/d.text/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def text(in_text):
5252

5353
for i in range(36):
5454
font(fonts[int(i % len(fonts))])
55-
size((36 - i if ((i >= 9 and i <= 18) or i > 27) else i) % 9)
55+
size((36 - i if ((9 <= i <= 18) or i > 27) else i) % 9)
5656
rotate(i * 10)
5757
color(colors[i % len(colors)])
5858
xy(

gui/wxpython/core/debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def msg(self, level, message, *args):
6161
:param args: formatting params
6262
"""
6363
# self.SetLevel()
64-
if self.debuglevel > 0 and level > 0 and level <= self.debuglevel:
64+
if 0 < level <= self.debuglevel:
6565
if args:
6666
sys.stderr.write(
6767
"GUI D%d/%d: " % (level, self.debuglevel)

gui/wxpython/core/gconsole.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def write(self, s):
316316

317317
if "GRASS_INFO_PERCENT" in line:
318318
value = int(line.rsplit(":", 1)[1].strip())
319-
progressValue = value if value >= 0 and value < 100 else 0
319+
progressValue = value if 0 <= value < 100 else 0
320320
elif "GRASS_INFO_MESSAGE" in line:
321321
self.type = "message"
322322
self.message += line.split(":", 1)[1].strip() + "\n"

gui/wxpython/core/utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,7 @@ def GetValidLayerName(name):
217217
cIdx = 0
218218
retNameList = list(retName)
219219
for c in retNameList:
220-
if (
221-
not (c >= "A" and c <= "Z")
222-
and not (c >= "a" and c <= "z")
223-
and not (c >= "0" and c <= "9")
224-
):
220+
if not ("A" <= c <= "Z") and not ("a" <= c <= "z") and not ("0" <= c <= "9"):
225221
retNameList[cIdx] = "_"
226222
cIdx += 1
227223
retName = "".join(retNameList)

gui/wxpython/mapwin/buffered.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,14 +555,14 @@ def TextBounds(self, textinfo, relcoords=False):
555555

556556
boxh = math.fabs(math.sin(math.radians(rotation)) * w) + h
557557
boxw = math.fabs(math.cos(math.radians(rotation)) * w) + h
558-
if rotation > 0 and rotation < 90:
558+
if 0 < rotation < 90:
559559
bbox[1] -= boxh
560560
relCoords = (0, boxh)
561-
elif rotation >= 90 and rotation < 180:
561+
elif 90 <= rotation < 180:
562562
bbox[0] -= boxw
563563
bbox[1] -= boxh
564564
relCoords = (boxw, boxh)
565-
elif rotation >= 180 and rotation < 270:
565+
elif 180 <= rotation < 270:
566566
bbox[0] -= boxw
567567
relCoords = (boxw, 0)
568568
bbox[2] = boxw

gui/wxpython/mapwin/graphics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def SetItemDrawOrder(self, item, drawNum):
363363
:return: True if order was changed
364364
:return: False if drawNum is out of range or item was not found
365365
"""
366-
if drawNum < len(self.itemsList) and drawNum >= 0 and item in self.itemsList:
366+
if 0 <= drawNum < len(self.itemsList) and item in self.itemsList:
367367
self.itemsList.insert(
368368
drawNum, self.itemsList.pop(self.itemsList.index(item))
369369
)

gui/wxpython/vdigit/wxdisplay.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def _validLine(self, line) -> bool:
563563
:return: True valid feature id
564564
:return: False invalid
565565
"""
566-
return bool(line > 0 and line <= Vect_get_num_lines(self.poMapInfo))
566+
return bool(0 < line <= Vect_get_num_lines(self.poMapInfo))
567567

568568
def SelectLinesByBox(self, bbox, ltype=None, drawSeg=False, poMapInfo=None):
569569
"""Select vector objects by given bounding box
@@ -913,7 +913,7 @@ def GetRegionSelected(self):
913913
for line in self.selected["ids"]:
914914
area = Vect_get_centroid_area(self.poMapInfo, line)
915915

916-
if area > 0 and area <= nareas:
916+
if 0 < area <= nareas:
917917
if not Vect_get_area_box(self.poMapInfo, area, byref(lineBox)):
918918
continue
919919
else: # noqa: PLR5501

gui/wxpython/vnet/vnet_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,4 +1450,4 @@ def IsInInterval(self, from_angle, to_angle, angle) -> bool:
14501450
if angle < from_angle:
14511451
angle = math.pi * 2 + angle
14521452

1453-
return bool(angle > from_angle and angle < to_angle)
1453+
return bool(from_angle < angle < to_angle)

gui/wxpython/vnet/widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def ShowColumn(self, colName, pos):
511511
:return: True if column was shown
512512
:return: False if position is not valid or column is not hidden
513513
"""
514-
if pos < 0 and pos >= self.self.GetColumnCount():
514+
if pos < 0 or pos >= self.GetColumnCount():
515515
return False
516516
if colName in self.hiddenCols:
517517
col = self.hiddenCols[colName]

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,6 @@ disable = [
639639
"R1713", # Consider using str.join(sequence) for concatenating strings from an iterable (consider-using-join)
640640
"R1714", # Consider merging these comparisons with 'in' by using '%s %sin (%s)'. Use a set instead if elements are hashable. (consider-using-in)
641641
"R1715", # Consider using dict.get for getting values from a dict if a key is present or a default if not (consider-using-get)
642-
"R1716", # Simplify chained comparison between the operands (chained-comparison)
643642
"R1724", # Unnecessary "%s" after "continue", %s (no-else-continue)
644643
"R1727", # Boolean condition '%s' will always evaluate to '%s' (condition-evals-to-constant)
645644
"R1732", # Consider using 'with' for resource-allocating operations (consider-using-with)

0 commit comments

Comments
 (0)