Skip to content

Commit b01a67d

Browse files
authored
style: Fix unnecessary-assign (RET504) (#4043)
1 parent 3b309db commit b01a67d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+90
-195
lines changed

gui/wxpython/core/utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1179,8 +1179,7 @@ def unregisterPid(pid):
11791179
def get_shell_pid(env=None):
11801180
"""Get shell PID from the GIS environment or None"""
11811181
try:
1182-
shell_pid = int(grass.gisenv(env=env)["PID"])
1183-
return shell_pid
1182+
return int(grass.gisenv(env=env)["PID"])
11841183
except (KeyError, ValueError) as error:
11851184
Debug.msg(
11861185
1, "No PID for GRASS shell (assuming no shell running): {}".format(error)

gui/wxpython/core/workspace.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ def __filterValue(self, value):
9292
:param value:
9393
"""
9494
value = value.replace("&lt;", "<")
95-
value = value.replace("&gt;", ">")
96-
97-
return value
95+
return value.replace("&gt;", ">")
9896

9997
def __getNodeText(self, node, tag, default=""):
10098
"""Get node text"""
@@ -1043,9 +1041,7 @@ def __filterValue(self, value):
10431041
"""Make value XML-valid"""
10441042
value = value.replace("<", "&lt;")
10451043
value = value.replace(">", "&gt;")
1046-
value = value.replace("&", "&amp;")
1047-
1048-
return value
1044+
return value.replace("&", "&amp;")
10491045

10501046
def __writeLayer(self, mapTree, item):
10511047
"""Write bunch of layers to GRASS Workspace XML file"""

gui/wxpython/datacatalog/tree.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,7 @@ def _getValidSavedGrassDBs(self):
359359
dbs = UserSettings.Get(
360360
group="datacatalog", key="grassdbs", subkey="listAsString"
361361
)
362-
dbs = [db for db in dbs.split(",") if os.path.isdir(db)]
363-
return dbs
362+
return [db for db in dbs.split(",") if os.path.isdir(db)]
364363

365364
def _saveGrassDBs(self):
366365
"""Save current grass dbs in tree to settings"""

gui/wxpython/gcp/manager.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ def _getOverWriteDialog(self, maptype, overwrite):
17921792
map_name = "<{}>".format(found["name"])
17931793

17941794
if found["name"] and not overwrite:
1795-
overwrite_dlg = wx.MessageDialog(
1795+
return wx.MessageDialog(
17961796
self.GetParent(),
17971797
message=_(
17981798
"The {map_type} map {map_name} exists. "
@@ -1804,7 +1804,6 @@ def _getOverWriteDialog(self, maptype, overwrite):
18041804
caption=_("Overwrite?"),
18051805
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
18061806
)
1807-
return overwrite_dlg
18081807

18091808
def OnGeorect(self, event):
18101809
"""

gui/wxpython/gmodeler/model.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -2027,9 +2027,7 @@ def _filterValue(self, value):
20272027
:param value:
20282028
"""
20292029
value = value.replace("&lt;", "<")
2030-
value = value.replace("&gt;", ">")
2031-
2032-
return value
2030+
return value.replace("&gt;", ">")
20332031

20342032
def _getNodeText(self, node, tag, default=""):
20352033
"""Get node text"""
@@ -2342,8 +2340,7 @@ def _filterValue(self, value):
23422340
:param value: string to be escaped as XML
23432341
:return: a XML-valid string
23442342
"""
2345-
value = saxutils.escape(value)
2346-
return value
2343+
return saxutils.escape(value)
23472344

23482345
def _header(self):
23492346
"""Write header"""

gui/wxpython/gui_core/dialogs.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1208,8 +1208,7 @@ def _filter(self, data):
12081208
"""Apply filter for strings in data list"""
12091209
flt_data = []
12101210
if len(self.flt_pattern) == 0:
1211-
flt_data = data[:]
1212-
return flt_data
1211+
return data[:]
12131212

12141213
for dt in data:
12151214
try:
@@ -1872,8 +1871,7 @@ def __init__(
18721871
def GetOpacity(self):
18731872
"""Button 'OK' pressed"""
18741873
# return opacity value
1875-
opacity = float(self.value.GetValue()) / 100
1876-
return opacity
1874+
return float(self.value.GetValue()) / 100
18771875

18781876
def OnApply(self, event):
18791877
self.applyOpacity.emit(value=self.GetOpacity())

gui/wxpython/gui_core/forms.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3062,8 +3062,7 @@ def AddBitmapToImageList(self, section, imageList):
30623062
image = wx.Image(iconSectionDict[section]).Scale(
30633063
16, 16, wx.IMAGE_QUALITY_HIGH
30643064
)
3065-
idx = imageList.Add(BitmapFromImage(image))
3066-
return idx
3065+
return imageList.Add(BitmapFromImage(image))
30673066

30683067
return -1
30693068

gui/wxpython/gui_core/gselect.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,7 @@ def AddItem(self, value, mapset=None, node=True, parent=None):
663663

664664
data = {"node": node, "mapset": mapset}
665665

666-
item = self.seltree.AppendItem(parent, text=value, data=data)
667-
return item
666+
return self.seltree.AppendItem(parent, text=value, data=data)
668667

669668
def OnKeyUp(self, event):
670669
"""Enables to select items using keyboard

gui/wxpython/gui_core/pyedit.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,7 @@ def _openFile(self, file_path):
301301
"""
302302
try:
303303
with open(file_path, "r") as f:
304-
content = f.read()
305-
return content
304+
return f.read()
306305
except PermissionError:
307306
GError(
308307
message=_(

gui/wxpython/gui_core/simplelmgr.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -377,31 +377,27 @@ def GetOptData(self, dcmd, layer, params, propwin):
377377

378378
def AddRaster(self, name, cmd, hidden, dialog):
379379
"""Ads new raster layer."""
380-
layer = self._layerList.AddNewLayer(
380+
return self._layerList.AddNewLayer(
381381
name=name, mapType="raster", active=True, cmd=cmd, hidden=hidden
382382
)
383-
return layer
384383

385384
def AddRast3d(self, name, cmd, hidden, dialog):
386385
"""Ads new raster3d layer."""
387-
layer = self._layerList.AddNewLayer(
386+
return self._layerList.AddNewLayer(
388387
name=name, mapType="raster_3d", active=True, cmd=cmd, hidden=hidden
389388
)
390-
return layer
391389

392390
def AddVector(self, name, cmd, hidden, dialog):
393391
"""Ads new vector layer."""
394-
layer = self._layerList.AddNewLayer(
392+
return self._layerList.AddNewLayer(
395393
name=name, mapType="vector", active=True, cmd=cmd, hidden=hidden
396394
)
397-
return layer
398395

399396
def AddRGB(self, name, cmd, hidden, dialog):
400397
"""Ads new vector layer."""
401-
layer = self._layerList.AddNewLayer(
398+
return self._layerList.AddNewLayer(
402399
name=name, mapType="rgb", active=True, cmd=cmd, hidden=hidden
403400
)
404-
return layer
405401

406402
def GetLayerInfo(self, layer, key):
407403
"""Just for compatibility, should be removed in the future"""

gui/wxpython/gui_core/treeview.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ def OnGetItemText(self, index, column=0):
9191
"""
9292
node = self._model.GetNodeByIndex(index)
9393
# remove & because of & needed in menu (&Files)
94-
label = node.label.replace("&", "")
95-
return label
94+
return node.label.replace("&", "")
9695

9796
def OnGetChildrenCount(self, index):
9897
"""Overridden method necessary to communicate with tree model."""
@@ -258,8 +257,7 @@ def OnGetItemText(self, index, column=0):
258257
if column > 0:
259258
return node.data.get(self._columns[column], "")
260259
else:
261-
label = node.label.replace("&", "")
262-
return label
260+
return node.label.replace("&", "")
263261

264262
def OnRightClick(self, event):
265263
"""Select item on right click.

gui/wxpython/gui_core/widgets.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1338,11 +1338,7 @@ def _searchModule(self, keys, value):
13381338
nodes.sort(key=self._model.GetIndexOfNode)
13391339
self._results = nodes
13401340
self._resultIndex = -1
1341-
commands = sorted(
1342-
[node.data["command"] for node in nodes if node.data["command"]]
1343-
)
1344-
1345-
return commands
1341+
return sorted([node.data["command"] for node in nodes if node.data["command"]])
13461342

13471343
def OnSelectModule(self, event=None):
13481344
"""Module selected from choice, update command prompt"""

gui/wxpython/history/tree.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,10 @@ def _timestampToDay(self, timestamp=None):
215215
return OLD_DATE
216216

217217
timestamp_datetime = datetime.datetime.fromisoformat(timestamp)
218-
day_midnight = datetime.datetime(
218+
return datetime.datetime(
219219
timestamp_datetime.year, timestamp_datetime.month, timestamp_datetime.day
220220
).date()
221221

222-
return day_midnight
223-
224222
def _initHistoryModel(self):
225223
"""Fill tree history model based on the current history log."""
226224
content_list = self.ReadFromHistory()

gui/wxpython/iclass/digit.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ def _getNewFeaturesLayer(self):
126126
return 1
127127

128128
def _getNewFeaturesCat(self):
129-
cat = self.mapWindow.GetCurrentCategory()
130-
return cat
129+
return self.mapWindow.GetCurrentCategory()
131130

132131
def DeleteAreasByCat(self, cats):
133132
"""Delete areas (centroid+boundaries) by categories

gui/wxpython/iscatt/frame.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ def _newScatterPlotName(self, scatt_id):
330330
return name
331331

332332
def _getScatterPlotName(self, i):
333-
name = "scatter plot %d" % i
334-
return name
333+
return "scatter plot %d" % i
335334

336335
def NewScatterPlot(self, scatt_id, transpose):
337336
# TODO needs to be resolved (should be in this class)

gui/wxpython/iscatt/iscatt_core.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,7 @@ def GetBandsInfo(self, scatt_id):
488488
b1_info = self.an_data.GetBandInfo(b1)
489489
b2_info = self.an_data.GetBandInfo(b2)
490490

491-
bands_info = {"b1": b1_info, "b2": b2_info}
492-
493-
return bands_info
491+
return {"b1": b1_info, "b2": b2_info}
494492

495493
def DeleScattPlot(self, cat_id, scatt_id):
496494
if cat_id not in self.cats:
@@ -784,15 +782,13 @@ def idBandsToidScatt(band_1_id, band_2_id, n_bands):
784782

785783
n_b1 = n_bands - 1
786784

787-
scatt_id = int(
785+
return int(
788786
(band_1_id * (2 * n_b1 + 1) - band_1_id * band_1_id) / 2
789787
+ band_2_id
790788
- band_1_id
791789
- 1
792790
)
793791

794-
return scatt_id
795-
796792

797793
def GetRegion():
798794
ret, region, msg = RunCommand("g.region", flags="gp", getErrorMsg=True, read=True)

gui/wxpython/iscatt/plots.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,7 @@ def GetCoords(self):
711711
if self.empty_pol:
712712
return None
713713

714-
coords = deepcopy(self.pol.xy)
715-
return coords
714+
return deepcopy(self.pol.xy)
716715

717716
def SetEmpty(self):
718717
self._setEmptyPol(True)

gui/wxpython/lmgr/frame.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2336,13 +2336,12 @@ def MsgDisplayResolution(self, limitText=None):
23362336
)
23372337
if limitText:
23382338
message += "\n\n%s" % _(limitText)
2339-
dlg = wx.MessageDialog(
2339+
return wx.MessageDialog(
23402340
parent=self,
23412341
message=message,
23422342
caption=_("Constrain map to region geometry?"),
23432343
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION | wx.CENTRE,
23442344
)
2345-
return dlg
23462345

23472346
def _onMapsetWatchdog(self, map_path, map_dest):
23482347
"""Current mapset watchdog event handler

gui/wxpython/lmgr/layertree.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2428,12 +2428,11 @@ def _createCommandCtrl(self):
24282428
height = 25
24292429
if sys.platform in {"win32", "darwin"}:
24302430
height = 40
2431-
ctrl = TextCtrl(
2431+
return TextCtrl(
24322432
self,
24332433
id=wx.ID_ANY,
24342434
value="",
24352435
pos=wx.DefaultPosition,
24362436
size=(self.GetSize()[0] - 100, height),
24372437
style=wx.TE_PROCESS_ENTER | wx.TE_DONTWRAP,
24382438
)
2439-
return ctrl

gui/wxpython/location_wizard/wizard.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,7 @@ def GetSortImages(self):
743743
def OnGetItemText(self, item, col):
744744
"""Get item text"""
745745
index = self.itemIndexMap[item]
746-
s = str(self.itemDataMap[index][col])
747-
return s
746+
return str(self.itemDataMap[index][col])
748747

749748
def OnGetItemImage(self, item):
750749
return -1
@@ -2795,9 +2794,7 @@ def CreateProj4String(self):
27952794
for item in datumparams:
27962795
proj4string = "%s +%s" % (proj4string, item)
27972796

2798-
proj4string = "%s +no_defs" % proj4string
2799-
2800-
return proj4string
2797+
return "%s +no_defs" % proj4string
28012798

28022799
def OnHelp(self, event):
28032800
"""'Help' button clicked"""

gui/wxpython/main_window/frame.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2430,13 +2430,12 @@ def MsgDisplayResolution(self, limitText=None):
24302430
)
24312431
if limitText:
24322432
message += "\n\n%s" % _(limitText)
2433-
dlg = wx.MessageDialog(
2433+
return wx.MessageDialog(
24342434
parent=self,
24352435
message=message,
24362436
caption=_("Constrain map to region geometry?"),
24372437
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION | wx.CENTRE,
24382438
)
2439-
return dlg
24402439

24412440
def _onMapsetWatchdog(self, map_path, map_dest):
24422441
"""Current mapset watchdog event handler

gui/wxpython/nviz/mapwindow.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def GetContentScaleFactor(self):
243243

244244
def InitFly(self):
245245
"""Initialize fly through dictionary"""
246-
fly = {
246+
return {
247247
"interval": 10, # interval for timerFly
248248
"value": [0, 0, 0], # calculated values for navigation
249249
"mode": 0, # fly through mode (0, 1)
@@ -264,8 +264,6 @@ def InitFly(self):
264264
"flySpeedStep": 2,
265265
}
266266

267-
return fly
268-
269267
def OnTimerFly(self, event):
270268
"""Fly event was emitted, move the scene"""
271269
if self.mouse["use"] != "fly":

gui/wxpython/nviz/wxnviz.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -2212,9 +2212,7 @@ def Load(self):
22122212
]
22132213
wx.EndBusyCursor()
22142214

2215-
id = Nviz_load_image(im, self.width, self.height, self.image.HasAlpha())
2216-
2217-
return id
2215+
return Nviz_load_image(im, self.width, self.height, self.image.HasAlpha())
22182216

22192217
def Draw(self):
22202218
"""Draw texture as an image"""

gui/wxpython/psmap/dialogs.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3200,8 +3200,7 @@ def getColsChoice(self, parent):
32003200
else:
32013201
cols = []
32023202

3203-
choice = Choice(parent=parent, id=wx.ID_ANY, choices=cols)
3204-
return choice
3203+
return Choice(parent=parent, id=wx.ID_ANY, choices=cols)
32053204

32063205
def update(self):
32073206
# feature type

gui/wxpython/psmap/frame.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -2613,9 +2613,7 @@ def ImageRect(self):
26132613
iH = iH * self.currScale
26142614
x = cW / 2 - iW / 2
26152615
y = cH / 2 - iH / 2
2616-
imageRect = Rect(int(x), int(y), int(iW), int(iH))
2617-
2618-
return imageRect
2616+
return Rect(int(x), int(y), int(iW), int(iH))
26192617

26202618
def RedrawSelectBox(self, id):
26212619
"""Redraws select box when selected object changes its size"""

gui/wxpython/psmap/instructions.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1913,8 +1913,7 @@ def __init__(self, id, env):
19131913
self.instruction = dict(self.defaultInstruction)
19141914

19151915
def __str__(self):
1916-
instr = string.Template("raster $raster").substitute(self.instruction)
1917-
return instr
1916+
return string.Template("raster $raster").substitute(self.instruction)
19181917

19191918
def Read(self, instruction, text):
19201919
"""Read instruction and save information"""

0 commit comments

Comments
 (0)