Skip to content

Commit e9b8764

Browse files
echoixa0x8o
authored andcommitted
style: Fixes if-stmt-min-max (PLR1730) (OSGeo#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 b120cf7 commit e9b8764

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
@@ -2293,14 +2293,10 @@ def GetNewExtent(self, region, map=None):
22932293
e, n = errlist[i].split()
22942294
fe = float(e)
22952295
fn = float(n)
2296-
if fe < newreg["w"]:
2297-
newreg["w"] = fe
2298-
if fe > newreg["e"]:
2299-
newreg["e"] = fe
2300-
if fn < newreg["s"]:
2301-
newreg["s"] = fn
2302-
if fn > newreg["n"]:
2303-
newreg["n"] = fn
2296+
newreg["w"] = min(fe, newreg["w"])
2297+
newreg["e"] = max(fe, newreg["e"])
2298+
newreg["s"] = min(fn, newreg["s"])
2299+
newreg["n"] = max(fn, newreg["n"])
23042300

23052301
return newreg
23062302

@@ -2349,10 +2345,8 @@ def AdjustMap(self, newreg):
23492345

23502346
# LL locations
23512347
if self.Map.projinfo["proj"] == "ll":
2352-
if newreg["n"] > 90.0:
2353-
newreg["n"] = 90.0
2354-
if newreg["s"] < -90.0:
2355-
newreg["s"] = -90.0
2348+
newreg["n"] = min(newreg["n"], 90.0)
2349+
newreg["s"] = max(newreg["s"], -90.0)
23562350

23572351
ce = newreg["w"] + (newreg["e"] - newreg["w"]) / 2
23582352
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
@@ -700,10 +700,8 @@ def OnKeyPressed(self, event):
700700
self.cmdindex = self.cmdindex - 1
701701
if event.GetKeyCode() == wx.WXK_DOWN:
702702
self.cmdindex = self.cmdindex + 1
703-
if self.cmdindex < 0:
704-
self.cmdindex = 0
705-
if self.cmdindex > len(self.cmdbuffer) - 1:
706-
self.cmdindex = len(self.cmdbuffer) - 1
703+
self.cmdindex = max(self.cmdindex, 0)
704+
self.cmdindex = min(self.cmdindex, len(self.cmdbuffer) - 1)
707705

708706
try:
709707
# without strip causes problem on windows

gui/wxpython/image2target/ii2t_manager.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -2231,14 +2231,10 @@ def GetNewExtent(self, region, map=None):
22312231
e, n = errlist[i].split()
22322232
fe = float(e)
22332233
fn = float(n)
2234-
if fe < newreg["w"]:
2235-
newreg["w"] = fe
2236-
if fe > newreg["e"]:
2237-
newreg["e"] = fe
2238-
if fn < newreg["s"]:
2239-
newreg["s"] = fn
2240-
if fn > newreg["n"]:
2241-
newreg["n"] = fn
2234+
newreg["w"] = min(fe, newreg["w"])
2235+
newreg["e"] = max(fe, newreg["e"])
2236+
newreg["s"] = min(fn, newreg["s"])
2237+
newreg["n"] = max(fn, newreg["n"])
22422238

22432239
return newreg
22442240

@@ -2287,10 +2283,8 @@ def AdjustMap(self, newreg):
22872283

22882284
# LL locations
22892285
if self.Map.projinfo["proj"] == "ll":
2290-
if newreg["n"] > 90.0:
2291-
newreg["n"] = 90.0
2292-
if newreg["s"] < -90.0:
2293-
newreg["s"] = -90.0
2286+
newreg["n"] = min(newreg["n"], 90.0)
2287+
newreg["s"] = max(newreg["s"], -90.0)
22942288

22952289
ce = newreg["w"] + (newreg["e"] - newreg["w"]) / 2
22962290
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
@@ -1512,14 +1512,10 @@ def GetNewExtent(self, region, map=None):
15121512
e, n = errlist[i].split()
15131513
fe = float(e)
15141514
fn = float(n)
1515-
if fe < newreg["w"]:
1516-
newreg["w"] = fe
1517-
if fe > newreg["e"]:
1518-
newreg["e"] = fe
1519-
if fn < newreg["s"]:
1520-
newreg["s"] = fn
1521-
if fn > newreg["n"]:
1522-
newreg["n"] = fn
1515+
newreg["w"] = min(fe, newreg["w"])
1516+
newreg["e"] = max(fe, newreg["e"])
1517+
newreg["s"] = min(fn, newreg["s"])
1518+
newreg["n"] = max(fn, newreg["n"])
15231519

15241520
return newreg
15251521

@@ -1568,10 +1564,8 @@ def AdjustMap(self, newreg):
15681564

15691565
# LL locations
15701566
if self.Map.projinfo["proj"] == "ll":
1571-
if newreg["n"] > 90.0:
1572-
newreg["n"] = 90.0
1573-
if newreg["s"] < -90.0:
1574-
newreg["s"] = -90.0
1567+
newreg["n"] = min(newreg["n"], 90.0)
1568+
newreg["s"] = max(newreg["s"], -90.0)
15751569

15761570
ce = newreg["w"] + (newreg["e"] - newreg["w"]) / 2
15771571
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
@@ -193,8 +193,7 @@ def benchmark_single(module, label, repeat=5):
193193
measured_times.append(module.time)
194194

195195
avg = time_sum / repeat
196-
if avg < min_avg:
197-
min_avg = avg
196+
min_avg = min(avg, min_avg)
198197
print(f"\nResult - {avg}s")
199198

200199
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
@@ -993,55 +993,43 @@ def compute_common_absolute_time_granularity_simple(gran_list):
993993

994994
if gran in ["seconds", "second"]:
995995
has_seconds = True
996-
if min_gran > 0:
997-
min_gran = 0
998-
if max_gran < 0:
999-
max_gran = 0
996+
min_gran = min(min_gran, 0)
997+
max_gran = max(max_gran, 0)
1000998

1001999
seconds.append(int(num))
10021000

10031001
if gran in ["minutes", "minute"]:
10041002
has_minutes = True
1005-
if min_gran > 1:
1006-
min_gran = 1
1007-
if max_gran < 1:
1008-
max_gran = 1
1003+
min_gran = min(min_gran, 1)
1004+
max_gran = max(max_gran, 1)
10091005

10101006
minutes.append(int(num))
10111007

10121008
if gran in ["hours", "hour"]:
10131009
has_hours = True
1014-
if min_gran > 2:
1015-
min_gran = 2
1016-
if max_gran < 2:
1017-
max_gran = 2
1010+
min_gran = min(min_gran, 2)
1011+
max_gran = max(max_gran, 2)
10181012

10191013
hours.append(int(num))
10201014

10211015
if gran in ["days", "day"]:
10221016
has_days = True
1023-
if min_gran > 3:
1024-
min_gran = 3
1025-
if max_gran < 3:
1026-
max_gran = 3
1017+
min_gran = min(min_gran, 3)
1018+
max_gran = max(max_gran, 3)
10271019

10281020
days.append(int(num))
10291021

10301022
if gran in ["months", "month"]:
10311023
has_months = True
1032-
if min_gran > 4:
1033-
min_gran = 4
1034-
if max_gran < 4:
1035-
max_gran = 4
1024+
min_gran = min(min_gran, 4)
1025+
max_gran = max(max_gran, 4)
10361026

10371027
months.append(int(num))
10381028

10391029
if gran in ["years", "year"]:
10401030
has_years = True
1041-
if min_gran > 5:
1042-
min_gran = 5
1043-
if max_gran < 5:
1044-
max_gran = 5
1031+
min_gran = min(min_gran, 5)
1032+
max_gran = max(max_gran, 5)
10451033

10461034
years.append(int(num))
10471035

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)