Skip to content

Commit ce1a43c

Browse files
authored
style: Fixes if-stmt-min-max (PLR1730) (#3950)
Concerns Pylint rules "consider-using-min-builtin / R1730" and "consider-using-max-builtin / R1731" Using `ruff check --output-format=concise --select PLR1730 --preview --fix`.
1 parent 837b796 commit ce1a43c

File tree

24 files changed

+76
-152
lines changed

24 files changed

+76
-152
lines changed

gui/wxpython/core/gcmd.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ def _recv(self, which, maxsize):
238238
try:
239239
x = msvcrt.get_osfhandle(conn.fileno())
240240
(read, nAvail, nMessage) = PeekNamedPipe(x, 0)
241-
if maxsize < nAvail:
242-
nAvail = maxsize
241+
nAvail = min(maxsize, nAvail)
243242
if nAvail > 0:
244243
(errCode, read) = ReadFile(x, nAvail, None)
245244
except ValueError:
@@ -301,8 +300,7 @@ def _recv(self, which, maxsize):
301300

302301

303302
def recv_some(p, t=0.1, e=1, tr=5, stderr=0):
304-
if tr < 1:
305-
tr = 1
303+
tr = max(tr, 1)
306304
x = time.time() + t
307305
y = []
308306
r = ""

gui/wxpython/dbmgr/base.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,8 @@ def LoadData(self, layer, columns=None, where=None, sql=None):
360360
i = 0
361361
for col in columns:
362362
width = self.columns[col]["length"] * 6 # FIXME
363-
if width < 60:
364-
width = 60
365-
if width > 300:
366-
width = 300
363+
width = max(width, 60)
364+
width = min(width, 300)
367365
self.SetColumnWidth(col=i, width=width)
368366
i += 1
369367

gui/wxpython/gcp/manager.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -2236,14 +2236,10 @@ def GetNewExtent(self, region, map=None):
22362236
e, n = errlist[i].split()
22372237
fe = float(e)
22382238
fn = float(n)
2239-
if fe < newreg["w"]:
2240-
newreg["w"] = fe
2241-
if fe > newreg["e"]:
2242-
newreg["e"] = fe
2243-
if fn < newreg["s"]:
2244-
newreg["s"] = fn
2245-
if fn > newreg["n"]:
2246-
newreg["n"] = fn
2239+
newreg["w"] = min(fe, newreg["w"])
2240+
newreg["e"] = max(fe, newreg["e"])
2241+
newreg["s"] = min(fn, newreg["s"])
2242+
newreg["n"] = max(fn, newreg["n"])
22472243

22482244
return newreg
22492245

@@ -2292,10 +2288,8 @@ def AdjustMap(self, newreg):
22922288

22932289
# LL locations
22942290
if self.Map.projinfo["proj"] == "ll":
2295-
if newreg["n"] > 90.0:
2296-
newreg["n"] = 90.0
2297-
if newreg["s"] < -90.0:
2298-
newreg["s"] = -90.0
2291+
newreg["n"] = min(newreg["n"], 90.0)
2292+
newreg["s"] = max(newreg["s"], -90.0)
22992293

23002294
ce = newreg["w"] + (newreg["e"] - newreg["w"]) / 2
23012295
cn = newreg["s"] + (newreg["n"] - newreg["s"]) / 2

gui/wxpython/gcp/statusbar.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ def Update(self):
9797
and sets the spin limits accordingly."""
9898
self.statusbar.SetStatusText("")
9999
maximum = self.mapFrame.GetListCtrl().GetItemCount()
100-
if maximum < 1:
101-
maximum = 1
100+
maximum = max(maximum, 1)
102101
self.widget.SetRange(0, maximum)
103102
self.Show()
104103

gui/wxpython/gmodeler/canvas.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ def GetNewShapePos(self, yoffset=50):
103103
ymax = 20
104104
for item in self.GetDiagram().GetShapeList():
105105
y = item.GetY() + item.GetBoundingBoxMin()[1]
106-
if y > ymax:
107-
ymax = y
106+
ymax = max(y, ymax)
108107

109108
return (self.GetSize()[0] // 2, ymax + yoffset)
110109

gui/wxpython/gmodeler/panels.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -989,14 +989,10 @@ def OnExportImage(self, event):
989989
xmax = x + w / 2
990990
ymin = y - h / 2
991991
ymax = y + h / 2
992-
if xmin < xminImg:
993-
xminImg = xmin
994-
if xmax > xmaxImg:
995-
xmaxImg = xmax
996-
if ymin < yminImg:
997-
yminImg = ymin
998-
if ymax > ymaxImg:
999-
ymaxImg = ymax
992+
xminImg = min(xmin, xminImg)
993+
xmaxImg = max(xmax, xmaxImg)
994+
yminImg = min(ymin, yminImg)
995+
ymaxImg = max(ymax, ymaxImg)
1000996
size = wx.Size(int(xmaxImg - xminImg) + 50, int(ymaxImg - yminImg) + 50)
1001997
bitmap = EmptyBitmap(width=size.width, height=size.height)
1002998

gui/wxpython/gui_core/prompt.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,8 @@ def OnKeyPressed(self, event):
480480
self.cmdindex = self.cmdindex - 1
481481
if event.GetKeyCode() == wx.WXK_DOWN:
482482
self.cmdindex = self.cmdindex + 1
483-
if self.cmdindex < 0:
484-
self.cmdindex = 0
485-
if self.cmdindex > len(self.cmdbuffer) - 1:
486-
self.cmdindex = len(self.cmdbuffer) - 1
483+
self.cmdindex = max(self.cmdindex, 0)
484+
self.cmdindex = min(self.cmdindex, len(self.cmdbuffer) - 1)
487485

488486
try:
489487
# without strip causes problem on windows

gui/wxpython/image2target/ii2t_manager.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -2174,14 +2174,10 @@ def GetNewExtent(self, region, map=None):
21742174
e, n = errlist[i].split()
21752175
fe = float(e)
21762176
fn = float(n)
2177-
if fe < newreg["w"]:
2178-
newreg["w"] = fe
2179-
if fe > newreg["e"]:
2180-
newreg["e"] = fe
2181-
if fn < newreg["s"]:
2182-
newreg["s"] = fn
2183-
if fn > newreg["n"]:
2184-
newreg["n"] = fn
2177+
newreg["w"] = min(fe, newreg["w"])
2178+
newreg["e"] = max(fe, newreg["e"])
2179+
newreg["s"] = min(fn, newreg["s"])
2180+
newreg["n"] = max(fn, newreg["n"])
21852181

21862182
return newreg
21872183

@@ -2230,10 +2226,8 @@ def AdjustMap(self, newreg):
22302226

22312227
# LL locations
22322228
if self.Map.projinfo["proj"] == "ll":
2233-
if newreg["n"] > 90.0:
2234-
newreg["n"] = 90.0
2235-
if newreg["s"] < -90.0:
2236-
newreg["s"] = -90.0
2229+
newreg["n"] = min(newreg["n"], 90.0)
2230+
newreg["s"] = max(newreg["s"], -90.0)
22372231

22382232
ce = newreg["w"] + (newreg["e"] - newreg["w"]) / 2
22392233
cn = newreg["s"] + (newreg["n"] - newreg["s"]) / 2

gui/wxpython/image2target/ii2t_statusbar.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ def Update(self):
9797
and sets the spin limits accordingly."""
9898
self.statusbar.SetStatusText("")
9999
maximum = self.mapFrame.GetListCtrl().GetItemCount()
100-
if maximum < 1:
101-
maximum = 1
100+
maximum = max(maximum, 1)
102101
self.widget.SetRange(0, maximum)
103102
self.Show()
104103

gui/wxpython/location_wizard/dialogs.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -703,11 +703,9 @@ def __init__(
703703
width = max(width, w)
704704

705705
height = height + 5
706-
if height > 400:
707-
height = 400
706+
height = min(height, 400)
708707
width = width + 5
709-
if width > 400:
710-
width = 400
708+
width = min(width, 400)
711709

712710
#
713711
# VListBox for displaying and selecting transformations

gui/wxpython/modules/colorrules.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -728,10 +728,8 @@ def ReadColorTable(self, ctable):
728728
self.rulesPanel.mainPanel.FindWindowById(count + 2000).SetColour(rgb)
729729
# range
730730
try:
731-
if float(value) < minim:
732-
minim = float(value)
733-
if float(value) > maxim:
734-
maxim = float(value)
731+
minim = min(float(value), minim)
732+
maxim = max(float(value), maxim)
735733
except ValueError: # nv, default
736734
pass
737735
count += 1
@@ -1619,10 +1617,8 @@ def LoadRulesFromColumn(self):
16191617
else:
16201618
col1, col2 = record.split(sep)
16211619

1622-
if float(col1) < minim:
1623-
minim = float(col1)
1624-
if float(col1) > maxim:
1625-
maxim = float(col1)
1620+
minim = min(float(col1), minim)
1621+
maxim = max(float(col1), maxim)
16261622

16271623
# color rules list should only have unique values of col1, not all
16281624
# records

gui/wxpython/nviz/tools.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2790,8 +2790,7 @@ def UpdateFrameIndex(
27902790
frameCount = anim.GetFrameCount()
27912791
if index >= frameCount:
27922792
index = frameCount - 1
2793-
if index < 0:
2794-
index = 0
2793+
index = max(index, 0)
27952794

27962795
if sliderWidget:
27972796
slider = self.FindWindowById(self.win["anim"]["frameIndex"]["slider"])

gui/wxpython/photo2image/ip2i_manager.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -1455,14 +1455,10 @@ def GetNewExtent(self, region, map=None):
14551455
e, n = errlist[i].split()
14561456
fe = float(e)
14571457
fn = float(n)
1458-
if fe < newreg["w"]:
1459-
newreg["w"] = fe
1460-
if fe > newreg["e"]:
1461-
newreg["e"] = fe
1462-
if fn < newreg["s"]:
1463-
newreg["s"] = fn
1464-
if fn > newreg["n"]:
1465-
newreg["n"] = fn
1458+
newreg["w"] = min(fe, newreg["w"])
1459+
newreg["e"] = max(fe, newreg["e"])
1460+
newreg["s"] = min(fn, newreg["s"])
1461+
newreg["n"] = max(fn, newreg["n"])
14661462

14671463
return newreg
14681464

@@ -1511,10 +1507,8 @@ def AdjustMap(self, newreg):
15111507

15121508
# LL locations
15131509
if self.Map.projinfo["proj"] == "ll":
1514-
if newreg["n"] > 90.0:
1515-
newreg["n"] = 90.0
1516-
if newreg["s"] < -90.0:
1517-
newreg["s"] = -90.0
1510+
newreg["n"] = min(newreg["n"], 90.0)
1511+
newreg["s"] = max(newreg["s"], -90.0)
15181512

15191513
ce = newreg["w"] + (newreg["e"] - newreg["w"]) / 2
15201514
cn = newreg["s"] + (newreg["n"] - newreg["s"]) / 2

gui/wxpython/photo2image/ip2i_statusbar.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ def Update(self):
9797
and sets the spin limits accordingly."""
9898
self.statusbar.SetStatusText("")
9999
maximum = self.mapFrame.GetListCtrl().GetItemCount()
100-
if maximum < 1:
101-
maximum = 1
100+
maximum = max(maximum, 1)
102101
self.widget.SetRange(0, maximum)
103102
self.Show()
104103

gui/wxpython/vnet/dialogs.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1743,8 +1743,7 @@ def AddStatusItem(self, text, key, priority):
17431743
if item["key"] == statusTextItem["key"]:
17441744
self.statusItems.remove(item)
17451745
self.statusItems.append(statusTextItem)
1746-
if self.maxPriority < statusTextItem["priority"]:
1747-
self.maxPriority = statusTextItem["priority"]
1746+
self.maxPriority = max(self.maxPriority, statusTextItem["priority"])
17481747
self._updateStatus()
17491748

17501749
def _updateStatus(self):
@@ -1770,8 +1769,7 @@ def RemoveStatusItem(self, key):
17701769
if update:
17711770
for item in self.statusItems:
17721771
self.maxPriority = 0
1773-
if self.maxPriority < item["priority"]:
1774-
self.maxPriority = item["priority"]
1772+
self.maxPriority = max(self.maxPriority, item["priority"])
17751773
self._updateStatus()
17761774

17771775

python/grass/benchmark/runners.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ def benchmark_single(module, label, repeat=5):
5555
measured_times.append(module.time)
5656

5757
avg = time_sum / repeat
58-
if avg < min_avg:
59-
min_avg = avg
58+
min_avg = min(avg, min_avg)
6059
print(f"\nResult - {avg}s")
6160

6261
print("\u2500" * term_size.columns)

python/grass/imaging/images2swf.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,7 @@ def twitsToBits(arr):
341341
maxlen = 1
342342
for i in arr:
343343
tmp = len(signedIntToBits(i * 20))
344-
if tmp > maxlen:
345-
maxlen = tmp
344+
maxlen = max(tmp, maxlen)
346345

347346
# build array
348347
bits = intToBits(maxlen, 5)

python/grass/jupyter/region.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,10 @@ def _set_bbox(self, env):
114114
west = float(bbox["ll_w"])
115115
north = float(bbox["ll_n"])
116116
east = float(bbox["ll_e"])
117-
if self._bbox[0][0] > south:
118-
self._bbox[0][0] = south
119-
if self._bbox[0][1] > west:
120-
self._bbox[0][1] = west
121-
if self._bbox[1][0] < north:
122-
self._bbox[1][0] = north
123-
if self._bbox[1][1] < east:
124-
self._bbox[1][1] = east
117+
self._bbox[0][0] = min(self._bbox[0][0], south)
118+
self._bbox[0][1] = min(self._bbox[0][1], west)
119+
self._bbox[1][0] = max(self._bbox[1][0], north)
120+
self._bbox[1][1] = max(self._bbox[1][1], east)
125121

126122

127123
class RegionManagerFor2D:

python/grass/temporal/temporal_granularity.py

+12-24
Original file line numberDiff line numberDiff line change
@@ -948,55 +948,43 @@ def compute_common_absolute_time_granularity_simple(gran_list):
948948

949949
if gran in ["seconds", "second"]:
950950
has_seconds = True
951-
if min_gran > 0:
952-
min_gran = 0
953-
if max_gran < 0:
954-
max_gran = 0
951+
min_gran = min(min_gran, 0)
952+
max_gran = max(max_gran, 0)
955953

956954
seconds.append(int(num))
957955

958956
if gran in ["minutes", "minute"]:
959957
has_minutes = True
960-
if min_gran > 1:
961-
min_gran = 1
962-
if max_gran < 1:
963-
max_gran = 1
958+
min_gran = min(min_gran, 1)
959+
max_gran = max(max_gran, 1)
964960

965961
minutes.append(int(num))
966962

967963
if gran in ["hours", "hour"]:
968964
has_hours = True
969-
if min_gran > 2:
970-
min_gran = 2
971-
if max_gran < 2:
972-
max_gran = 2
965+
min_gran = min(min_gran, 2)
966+
max_gran = max(max_gran, 2)
973967

974968
hours.append(int(num))
975969

976970
if gran in ["days", "day"]:
977971
has_days = True
978-
if min_gran > 3:
979-
min_gran = 3
980-
if max_gran < 3:
981-
max_gran = 3
972+
min_gran = min(min_gran, 3)
973+
max_gran = max(max_gran, 3)
982974

983975
days.append(int(num))
984976

985977
if gran in ["months", "month"]:
986978
has_months = True
987-
if min_gran > 4:
988-
min_gran = 4
989-
if max_gran < 4:
990-
max_gran = 4
979+
min_gran = min(min_gran, 4)
980+
max_gran = max(max_gran, 4)
991981

992982
months.append(int(num))
993983

994984
if gran in ["years", "year"]:
995985
has_years = True
996-
if min_gran > 5:
997-
min_gran = 5
998-
if max_gran < 5:
999-
max_gran = 5
986+
min_gran = min(min_gran, 5)
987+
max_gran = max(max_gran, 5)
1000988

1001989
years.append(int(num))
1002990

scripts/d.correlate/d.correlate.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,10 @@ def main():
8383
minx = maxx = x
8484
miny = maxy = y
8585
first = False
86-
if minx > x:
87-
minx = x
88-
if maxx < x:
89-
maxx = x
90-
if miny > y:
91-
miny = y
92-
if maxy < y:
93-
maxy = y
86+
minx = min(minx, x)
87+
maxx = max(maxx, x)
88+
miny = min(miny, y)
89+
maxy = max(maxy, y)
9490
ifile.close()
9591

9692
kx = 100.0 / (maxx - minx + 1)

0 commit comments

Comments
 (0)