Skip to content

Commit

Permalink
wxGUI: Fix E722 Warnings by Specifying Exception Types in dbmgr/ (#4382)
Browse files Browse the repository at this point in the history
  • Loading branch information
arohanajit authored Sep 26, 2024
1 parent 549ea90 commit edea810
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
3 changes: 0 additions & 3 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ per-file-ignores =
doc/python/m.distance.py: E501
doc/gui/wxpython/example/dialogs.py: F401
gui/scripts/d.wms.py: E501
gui/wxpython/dbmgr/base.py: E722
gui/wxpython/dbmgr/sqlbuilder.py: E722
gui/wxpython/dbmgr/manager.py: E722
gui/wxpython/docs/wxgui_sphinx/conf.py: E402, W291
gui/wxpython/gcp/manager.py: E722
gui/wxpython/gui_core/*: E722
Expand Down
23 changes: 15 additions & 8 deletions gui/wxpython/dbmgr/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def LoadData(self, layer, columns=None, where=None, sql=None):
try:
# for maps connected via v.external
keyId = columns.index(keyColumn)
except:
except ValueError:
keyId = -1

# read data
Expand Down Expand Up @@ -961,7 +961,7 @@ def OnLayerPageChanged(self, event):
self.layerPage[self.selLayer]["data"]
).GetItemCount()
)
except:
except Exception:
pass

if idCol:
Expand Down Expand Up @@ -1640,7 +1640,7 @@ def OnDataItemAdd(self, event):
if dlg.ShowModal() == wx.ID_OK:
try: # get category number
cat = int(dlg.GetValues(columns=[keyColumn])[0])
except:
except ValueError:
cat = -1

try:
Expand Down Expand Up @@ -1672,14 +1672,21 @@ def OnDataItemAdd(self, event):
values[i] = int(float(values[i]))
elif tlist.columns[columnName[i]]["ctype"] == float:
values[i] = float(values[i])
except:
except ValueError:
raise ValueError(
_("Value '%(value)s' needs to be entered as %(type)s.")
% {
"value": values[i],
"type": tlist.columns[columnName[i]]["type"],
}
)
except KeyError:
raise KeyError(
_("Column '%(column)s' does not exist.")
% {
"column": columnName[i],
}
)
columnsString += "%s," % columnName[i]

if tlist.columns[columnName[i]]["ctype"] == str:
Expand Down Expand Up @@ -3809,7 +3816,7 @@ def OnDeleteLayer(self, event):
"""Delete layer"""
try:
layer = int(self.deleteLayer.GetValue())
except:
except ValueError:
return

RunCommand(
Expand Down Expand Up @@ -3856,10 +3863,10 @@ def OnChangeLayer(self, event):
"""Layer number of layer to be deleted is changed"""
try:
layer = int(event.GetString())
except:
except ValueError:
try:
layer = self.mapDBInfo.layers.keys()[0]
except:
layer = list(self.mapDBInfo.layers.keys())[0]
except IndexError:
return

if self.GetCurrentPage() == self.modifyPanel:
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/dbmgr/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(
self.parent = parent
try:
mapdisplay = self.parent.GetMapDisplay()
except:
except AttributeError:
mapdisplay = None

DbMgrBase.__init__(
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/dbmgr/sqlbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def OnUniqueValues(self, event, justsample=False):
try:
idx = self.list_columns.GetSelections()[0]
column = self.list_columns.GetString(idx)
except:
except IndexError:
self.list_values.Clear()
return

Expand Down

0 comments on commit edea810

Please sign in to comment.