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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 6 additions & 12 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 4 additions & 8 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 6 additions & 12 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 2 additions & 4 deletions
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

0 commit comments

Comments
 (0)