Skip to content

Commit

Permalink
style: Fixes if-stmt-min-max (PLR1730) (OSGeo#3950)
Browse files Browse the repository at this point in the history
Concerns Pylint rules "consider-using-min-builtin / R1730" and "consider-using-max-builtin / R1731"

Using `ruff check --output-format=concise --select PLR1730 --preview --fix`.
  • Loading branch information
echoix authored and cyliang368 committed Jul 1, 2024
1 parent e6b0047 commit a056499
Show file tree
Hide file tree
Showing 24 changed files with 76 additions and 152 deletions.
6 changes: 2 additions & 4 deletions gui/wxpython/core/gcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ def _recv(self, which, maxsize):
try:
x = msvcrt.get_osfhandle(conn.fileno())
(read, nAvail, nMessage) = PeekNamedPipe(x, 0)
if maxsize < nAvail:
nAvail = maxsize
nAvail = min(maxsize, nAvail)
if nAvail > 0:
(errCode, read) = ReadFile(x, nAvail, None)
except ValueError:
Expand Down Expand Up @@ -301,8 +300,7 @@ def _recv(self, which, maxsize):


def recv_some(p, t=0.1, e=1, tr=5, stderr=0):
if tr < 1:
tr = 1
tr = max(tr, 1)
x = time.time() + t
y = []
r = ""
Expand Down
6 changes: 2 additions & 4 deletions gui/wxpython/dbmgr/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,8 @@ def LoadData(self, layer, columns=None, where=None, sql=None):
i = 0
for col in columns:
width = self.columns[col]["length"] * 6 # FIXME
if width < 60:
width = 60
if width > 300:
width = 300
width = max(width, 60)
width = min(width, 300)
self.SetColumnWidth(col=i, width=width)
i += 1

Expand Down
18 changes: 6 additions & 12 deletions gui/wxpython/gcp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2236,14 +2236,10 @@ def GetNewExtent(self, region, map=None):
e, n = errlist[i].split()
fe = float(e)
fn = float(n)
if fe < newreg["w"]:
newreg["w"] = fe
if fe > newreg["e"]:
newreg["e"] = fe
if fn < newreg["s"]:
newreg["s"] = fn
if fn > newreg["n"]:
newreg["n"] = fn
newreg["w"] = min(fe, newreg["w"])
newreg["e"] = max(fe, newreg["e"])
newreg["s"] = min(fn, newreg["s"])
newreg["n"] = max(fn, newreg["n"])

return newreg

Expand Down Expand Up @@ -2292,10 +2288,8 @@ def AdjustMap(self, newreg):

# LL locations
if self.Map.projinfo["proj"] == "ll":
if newreg["n"] > 90.0:
newreg["n"] = 90.0
if newreg["s"] < -90.0:
newreg["s"] = -90.0
newreg["n"] = min(newreg["n"], 90.0)
newreg["s"] = max(newreg["s"], -90.0)

ce = newreg["w"] + (newreg["e"] - newreg["w"]) / 2
cn = newreg["s"] + (newreg["n"] - newreg["s"]) / 2
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/gcp/statusbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ def Update(self):
and sets the spin limits accordingly."""
self.statusbar.SetStatusText("")
maximum = self.mapFrame.GetListCtrl().GetItemCount()
if maximum < 1:
maximum = 1
maximum = max(maximum, 1)
self.widget.SetRange(0, maximum)
self.Show()

Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/gmodeler/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ def GetNewShapePos(self, yoffset=50):
ymax = 20
for item in self.GetDiagram().GetShapeList():
y = item.GetY() + item.GetBoundingBoxMin()[1]
if y > ymax:
ymax = y
ymax = max(y, ymax)

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

Expand Down
12 changes: 4 additions & 8 deletions gui/wxpython/gmodeler/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,14 +989,10 @@ def OnExportImage(self, event):
xmax = x + w / 2
ymin = y - h / 2
ymax = y + h / 2
if xmin < xminImg:
xminImg = xmin
if xmax > xmaxImg:
xmaxImg = xmax
if ymin < yminImg:
yminImg = ymin
if ymax > ymaxImg:
ymaxImg = ymax
xminImg = min(xmin, xminImg)
xmaxImg = max(xmax, xmaxImg)
yminImg = min(ymin, yminImg)
ymaxImg = max(ymax, ymaxImg)
size = wx.Size(int(xmaxImg - xminImg) + 50, int(ymaxImg - yminImg) + 50)
bitmap = EmptyBitmap(width=size.width, height=size.height)

Expand Down
6 changes: 2 additions & 4 deletions gui/wxpython/gui_core/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,8 @@ def OnKeyPressed(self, event):
self.cmdindex = self.cmdindex - 1
if event.GetKeyCode() == wx.WXK_DOWN:
self.cmdindex = self.cmdindex + 1
if self.cmdindex < 0:
self.cmdindex = 0
if self.cmdindex > len(self.cmdbuffer) - 1:
self.cmdindex = len(self.cmdbuffer) - 1
self.cmdindex = max(self.cmdindex, 0)
self.cmdindex = min(self.cmdindex, len(self.cmdbuffer) - 1)

try:
# without strip causes problem on windows
Expand Down
18 changes: 6 additions & 12 deletions gui/wxpython/image2target/ii2t_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2174,14 +2174,10 @@ def GetNewExtent(self, region, map=None):
e, n = errlist[i].split()
fe = float(e)
fn = float(n)
if fe < newreg["w"]:
newreg["w"] = fe
if fe > newreg["e"]:
newreg["e"] = fe
if fn < newreg["s"]:
newreg["s"] = fn
if fn > newreg["n"]:
newreg["n"] = fn
newreg["w"] = min(fe, newreg["w"])
newreg["e"] = max(fe, newreg["e"])
newreg["s"] = min(fn, newreg["s"])
newreg["n"] = max(fn, newreg["n"])

return newreg

Expand Down Expand Up @@ -2230,10 +2226,8 @@ def AdjustMap(self, newreg):

# LL locations
if self.Map.projinfo["proj"] == "ll":
if newreg["n"] > 90.0:
newreg["n"] = 90.0
if newreg["s"] < -90.0:
newreg["s"] = -90.0
newreg["n"] = min(newreg["n"], 90.0)
newreg["s"] = max(newreg["s"], -90.0)

ce = newreg["w"] + (newreg["e"] - newreg["w"]) / 2
cn = newreg["s"] + (newreg["n"] - newreg["s"]) / 2
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/image2target/ii2t_statusbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ def Update(self):
and sets the spin limits accordingly."""
self.statusbar.SetStatusText("")
maximum = self.mapFrame.GetListCtrl().GetItemCount()
if maximum < 1:
maximum = 1
maximum = max(maximum, 1)
self.widget.SetRange(0, maximum)
self.Show()

Expand Down
6 changes: 2 additions & 4 deletions gui/wxpython/location_wizard/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,9 @@ def __init__(
width = max(width, w)

height = height + 5
if height > 400:
height = 400
height = min(height, 400)
width = width + 5
if width > 400:
width = 400
width = min(width, 400)

#
# VListBox for displaying and selecting transformations
Expand Down
12 changes: 4 additions & 8 deletions gui/wxpython/modules/colorrules.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,8 @@ def ReadColorTable(self, ctable):
self.rulesPanel.mainPanel.FindWindowById(count + 2000).SetColour(rgb)
# range
try:
if float(value) < minim:
minim = float(value)
if float(value) > maxim:
maxim = float(value)
minim = min(float(value), minim)
maxim = max(float(value), maxim)
except ValueError: # nv, default
pass
count += 1
Expand Down Expand Up @@ -1619,10 +1617,8 @@ def LoadRulesFromColumn(self):
else:
col1, col2 = record.split(sep)

if float(col1) < minim:
minim = float(col1)
if float(col1) > maxim:
maxim = float(col1)
minim = min(float(col1), minim)
maxim = max(float(col1), maxim)

# color rules list should only have unique values of col1, not all
# records
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/nviz/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2790,8 +2790,7 @@ def UpdateFrameIndex(
frameCount = anim.GetFrameCount()
if index >= frameCount:
index = frameCount - 1
if index < 0:
index = 0
index = max(index, 0)

if sliderWidget:
slider = self.FindWindowById(self.win["anim"]["frameIndex"]["slider"])
Expand Down
18 changes: 6 additions & 12 deletions gui/wxpython/photo2image/ip2i_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,14 +1455,10 @@ def GetNewExtent(self, region, map=None):
e, n = errlist[i].split()
fe = float(e)
fn = float(n)
if fe < newreg["w"]:
newreg["w"] = fe
if fe > newreg["e"]:
newreg["e"] = fe
if fn < newreg["s"]:
newreg["s"] = fn
if fn > newreg["n"]:
newreg["n"] = fn
newreg["w"] = min(fe, newreg["w"])
newreg["e"] = max(fe, newreg["e"])
newreg["s"] = min(fn, newreg["s"])
newreg["n"] = max(fn, newreg["n"])

return newreg

Expand Down Expand Up @@ -1511,10 +1507,8 @@ def AdjustMap(self, newreg):

# LL locations
if self.Map.projinfo["proj"] == "ll":
if newreg["n"] > 90.0:
newreg["n"] = 90.0
if newreg["s"] < -90.0:
newreg["s"] = -90.0
newreg["n"] = min(newreg["n"], 90.0)
newreg["s"] = max(newreg["s"], -90.0)

ce = newreg["w"] + (newreg["e"] - newreg["w"]) / 2
cn = newreg["s"] + (newreg["n"] - newreg["s"]) / 2
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/photo2image/ip2i_statusbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ def Update(self):
and sets the spin limits accordingly."""
self.statusbar.SetStatusText("")
maximum = self.mapFrame.GetListCtrl().GetItemCount()
if maximum < 1:
maximum = 1
maximum = max(maximum, 1)
self.widget.SetRange(0, maximum)
self.Show()

Expand Down
6 changes: 2 additions & 4 deletions gui/wxpython/vnet/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1743,8 +1743,7 @@ def AddStatusItem(self, text, key, priority):
if item["key"] == statusTextItem["key"]:
self.statusItems.remove(item)
self.statusItems.append(statusTextItem)
if self.maxPriority < statusTextItem["priority"]:
self.maxPriority = statusTextItem["priority"]
self.maxPriority = max(self.maxPriority, statusTextItem["priority"])
self._updateStatus()

def _updateStatus(self):
Expand All @@ -1770,8 +1769,7 @@ def RemoveStatusItem(self, key):
if update:
for item in self.statusItems:
self.maxPriority = 0
if self.maxPriority < item["priority"]:
self.maxPriority = item["priority"]
self.maxPriority = max(self.maxPriority, item["priority"])
self._updateStatus()


Expand Down
3 changes: 1 addition & 2 deletions python/grass/benchmark/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ def benchmark_single(module, label, repeat=5):
measured_times.append(module.time)

avg = time_sum / repeat
if avg < min_avg:
min_avg = avg
min_avg = min(avg, min_avg)
print(f"\nResult - {avg}s")

print("\u2500" * term_size.columns)
Expand Down
3 changes: 1 addition & 2 deletions python/grass/imaging/images2swf.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ def twitsToBits(arr):
maxlen = 1
for i in arr:
tmp = len(signedIntToBits(i * 20))
if tmp > maxlen:
maxlen = tmp
maxlen = max(tmp, maxlen)

# build array
bits = intToBits(maxlen, 5)
Expand Down
12 changes: 4 additions & 8 deletions python/grass/jupyter/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,10 @@ def _set_bbox(self, env):
west = float(bbox["ll_w"])
north = float(bbox["ll_n"])
east = float(bbox["ll_e"])
if self._bbox[0][0] > south:
self._bbox[0][0] = south
if self._bbox[0][1] > west:
self._bbox[0][1] = west
if self._bbox[1][0] < north:
self._bbox[1][0] = north
if self._bbox[1][1] < east:
self._bbox[1][1] = east
self._bbox[0][0] = min(self._bbox[0][0], south)
self._bbox[0][1] = min(self._bbox[0][1], west)
self._bbox[1][0] = max(self._bbox[1][0], north)
self._bbox[1][1] = max(self._bbox[1][1], east)


class RegionManagerFor2D:
Expand Down
36 changes: 12 additions & 24 deletions python/grass/temporal/temporal_granularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,55 +948,43 @@ def compute_common_absolute_time_granularity_simple(gran_list):

if gran in ["seconds", "second"]:
has_seconds = True
if min_gran > 0:
min_gran = 0
if max_gran < 0:
max_gran = 0
min_gran = min(min_gran, 0)
max_gran = max(max_gran, 0)

seconds.append(int(num))

if gran in ["minutes", "minute"]:
has_minutes = True
if min_gran > 1:
min_gran = 1
if max_gran < 1:
max_gran = 1
min_gran = min(min_gran, 1)
max_gran = max(max_gran, 1)

minutes.append(int(num))

if gran in ["hours", "hour"]:
has_hours = True
if min_gran > 2:
min_gran = 2
if max_gran < 2:
max_gran = 2
min_gran = min(min_gran, 2)
max_gran = max(max_gran, 2)

hours.append(int(num))

if gran in ["days", "day"]:
has_days = True
if min_gran > 3:
min_gran = 3
if max_gran < 3:
max_gran = 3
min_gran = min(min_gran, 3)
max_gran = max(max_gran, 3)

days.append(int(num))

if gran in ["months", "month"]:
has_months = True
if min_gran > 4:
min_gran = 4
if max_gran < 4:
max_gran = 4
min_gran = min(min_gran, 4)
max_gran = max(max_gran, 4)

months.append(int(num))

if gran in ["years", "year"]:
has_years = True
if min_gran > 5:
min_gran = 5
if max_gran < 5:
max_gran = 5
min_gran = min(min_gran, 5)
max_gran = max(max_gran, 5)

years.append(int(num))

Expand Down
12 changes: 4 additions & 8 deletions scripts/d.correlate/d.correlate.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,10 @@ def main():
minx = maxx = x
miny = maxy = y
first = False
if minx > x:
minx = x
if maxx < x:
maxx = x
if miny > y:
miny = y
if maxy < y:
maxy = y
minx = min(minx, x)
maxx = max(maxx, x)
miny = min(miny, y)
maxy = max(maxy, y)
ifile.close()

kx = 100.0 / (maxx - minx + 1)
Expand Down
Loading

0 comments on commit a056499

Please sign in to comment.