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

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
@@ -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

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
@@ -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

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

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)