Skip to content

Commit

Permalink
style: Fix self-assigning-variable (PLW0127) (OSGeo#4137)
Browse files Browse the repository at this point in the history
* style: Fix self-assigning-variable (PLW0127)

* PLW0127: python/grass/temporal/core.py: The last change on this line was removing decode(mapset) for python 3.

* temporal/t.rast.accumulate/t.rast.accumulate.py:283:13: PLW0127 Self-assignment of variable `upper`
Following the patterns from the same file, it seems that it is the map id that is wanted

* temporal/t.rast.accdetect/t.rast.accdetect.py:241:13: PLW0127 Self-assignment of variable `indicator`

Usage seemed to mean to set the map id instead.

* gui/wxpython/psmap/instructions.py: PLW0127 Self-assignment of variables in EstimateWidth, EstimateHeight, and EstimateSize

* gui/wxpython/psmap/frame.py:2234:17: PLW0127 Self-assignment of variable `zoomFactor`

* Change `not` usage to `<=`

* gui/wxpython/animation/temporal_manager.py:292:21: PLW0127 Self-assignment of variable `end`
Removed assignment

* Apply ruff suggestion for collapsible-else-if (PLR5501)
  • Loading branch information
echoix authored Aug 9, 2024
1 parent 16c5bf9 commit 1953975
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 47 deletions.
35 changes: 16 additions & 19 deletions gui/wxpython/animation/temporal_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,26 +288,23 @@ def _getLabelsAndMaps(self, timeseries):
followsPoint = True
lastTimeseries = series
end = None
else:
end = end
# interval data
if series:
# map exists, stop point mode
listOfMaps.append(series)
afterPoint = False
elif afterPoint:
# check point mode
if followsPoint:
# skip this one, already there
followsPoint = False
continue
else:
# append the last one (of point time)
listOfMaps.append(lastTimeseries)
end = None
elif series:
# map exists, stop point mode
listOfMaps.append(series)
afterPoint = False
elif afterPoint:
# check point mode
if followsPoint:
# skip this one, already there
followsPoint = False
continue
else:
# append series which is None
listOfMaps.append(series)
# append the last one (of point time)
listOfMaps.append(lastTimeseries)
end = None
else:
# append series which is None
listOfMaps.append(series)
timeLabels.append((start, end, unit))

return timeLabels, listOfMaps
Expand Down
4 changes: 1 addition & 3 deletions gui/wxpython/psmap/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2230,9 +2230,7 @@ def ComputeZoom(self, rect):
zoomFactor = 1
# when zooming to full extent, in some cases, there was zoom
# 1.01..., which causes problem
if abs(zoomFactor - 1) > 0.01:
zoomFactor = zoomFactor
else:
if abs(zoomFactor - 1) <= 0.01:
zoomFactor = 1.0

if self.mouse["use"] == "zoomout":
Expand Down
28 changes: 7 additions & 21 deletions gui/wxpython/psmap/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1733,17 +1733,13 @@ def Read(self, instruction, text, **kwargs):
def EstimateHeight(self, raster, discrete, fontsize, cols=None, height=None):
"""Estimate height to draw raster legend"""
if discrete == "n":
if height:
height = height
else:
if not height:
height = self.unitConv.convert(
value=fontsize * 10, fromUnit="point", toUnit="inch"
)

if discrete == "y":
if cols:
cols = cols
else:
if not cols:
cols = 1

rinfo = gs.raster_info(raster)
Expand Down Expand Up @@ -1772,9 +1768,7 @@ def EstimateWidth(
if discrete == "n":
rinfo = gs.raster_info(raster)
minim, maxim = rinfo["min"], rinfo["max"]
if width:
width = width
else:
if not width:
width = self.unitConv.convert(
value=fontsize * 2, fromUnit="point", toUnit="inch"
)
Expand All @@ -1785,14 +1779,10 @@ def EstimateWidth(
width += textPart

elif discrete == "y":
if cols:
cols = cols
else:
if not cols:
cols = 1

if width:
width = width
else:
if not width:
paperWidth = (
paperInstr["Width"] - paperInstr["Right"] - paperInstr["Left"]
)
Expand Down Expand Up @@ -1872,14 +1862,10 @@ def Read(self, instruction, text, **kwargs):

def EstimateSize(self, vectorInstr, fontsize, width=None, cols=None):
"""Estimate size to draw vector legend"""
if width:
width = width
else:
if not width:
width = fontsize / 24.0

if cols:
cols = cols
else:
if not cols:
cols = 1

vectors = vectorInstr["list"]
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ ignore = [
"PLR6104", # non-augmented-assignment
"PLR6201", # literal-membership
"PLR6301", # no-self-use
"PLW0127", # self-assigning-variable
"PLW0406", # import-self
"PLW0602", # global-variable-not-assigned
"PLW0603", # global-statement
Expand Down
1 change: 0 additions & 1 deletion python/grass/temporal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ def get_available_temporal_mapsets():
tgis_mapsets = {}

for mapset in mapsets:
mapset = mapset
driver = c_library_interface.get_driver_name(mapset)
database = c_library_interface.get_database_name(mapset)

Expand Down
2 changes: 1 addition & 1 deletion temporal/t.rast.accdetect/t.rast.accdetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def main():
)
)
if indicator.find("@") >= 0:
indicator = indicator
indicator_id = indicator
else:
indicator_id = indicator + "@" + mapset

Expand Down
2 changes: 1 addition & 1 deletion temporal/t.rast.accumulate/t.rast.accumulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def main():
)

if upper.find("@") >= 0:
upper = upper
upper_id = upper
else:
upper_id = upper + "@" + mapset

Expand Down

0 comments on commit 1953975

Please sign in to comment.