Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checks: Fix E722 do not use bare except #3748

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ per-file-ignores =
# F405 variable may be undefined, or defined from star imports
# E402 module level import not at top of file
# E501 line too long
# E722 do not use bare 'except'
# W605 invalid escape sequence
# F821 undefined name 'unicode'
# F841 local variable assigned to but never used
Expand Down
3 changes: 2 additions & 1 deletion gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import grass.script as gs
from grass.script import task as gtask
from grass.exceptions import ScriptError

from grass.pydispatch.signal import Signal

Expand Down Expand Up @@ -688,7 +689,7 @@ def load_source(modname, filename):
if len(command) == 1 and not skipInterface:
try:
task = gtask.parse_interface(command[0])
except Exception:
except ScriptError:
task = None
else:
task = None
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ def SetRegion(self, windres=False, windres3=False):

return grass_region

except Exception:
except (KeyError, TypeError):
return None

def GetListOfLayers(
Expand Down
8 changes: 7 additions & 1 deletion gui/wxpython/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ def _generateLocale(self):
self.locs.sort()
# Add a default choice to not override system locale
self.locs.insert(0, "system")
except Exception:
except (
KeyError,
FileNotFoundError,
PermissionError,
NotADirectoryError,
OSError,
):
# No NLS
self.locs = ["system"]

Expand Down
11 changes: 6 additions & 5 deletions gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from grass.script import core as grass
from grass.script import task as gtask
from grass.exceptions import CalledModuleError
from grass.app.runtime import get_grass_config_dir

from core.gcmd import RunCommand
Expand Down Expand Up @@ -76,7 +77,7 @@ def GetTempfile(pref=None):
if pref:
return os.path.join(pref, file)
return tempfile
except Exception:
except TypeError:
return None


Expand Down Expand Up @@ -254,7 +255,7 @@ def ListOfCatsToRange(cats):

try:
cats = list(map(int, cats))
except ValueError:
except (TypeError, ValueError):
return catstr

i = 0
Expand Down Expand Up @@ -575,7 +576,7 @@ def GetListOfLocations(dbase):
os.path.join(location, "*")
):
listOfLocations.append(os.path.basename(location))
except OSError:
except (TypeError, FileNotFoundError, PermissionError, NotADirectoryError):
pass

ListSortLower(listOfLocations)
Expand Down Expand Up @@ -628,7 +629,7 @@ def _getGDALFormats():
"""Get dictionary of available GDAL drivers"""
try:
ret = grass.read_command("r.in.gdal", quiet=True, flags="f")
except grass.CalledModuleError:
except CalledModuleError:
ret = None

return _parseFormats(ret), _parseFormats(ret, writableOnly=True)
Expand All @@ -638,7 +639,7 @@ def _getOGRFormats():
"""Get dictionary of available OGR drivers"""
try:
ret = grass.read_command("v.in.ogr", quiet=True, flags="f")
except grass.CalledModuleError:
except CalledModuleError:
ret = None

return _parseFormats(ret), _parseFormats(ret, writableOnly=True)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ def _get_value(self, line):
"""Get value of element"""
try:
return line.strip(" ").split(" ")[1].strip(" ")
except IndexError:
except (IndexError, AttributeError):
return ""

def _get_element(self, line):
Expand Down
3 changes: 2 additions & 1 deletion gui/wxpython/dbmgr/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3075,6 +3075,7 @@ class LayerBook(wx.Notebook):
def __init__(self, parent, id, parentDialog, style=wx.BK_DEFAULT):
wx.Notebook.__init__(self, parent, id, style=style)

self.delet6yeLayer = None
self.parent = parent
self.parentDialog = parentDialog
self.mapDBInfo = self.parentDialog.dbMgrData["mapDBInfo"]
Expand Down Expand Up @@ -3839,7 +3840,7 @@ def OnChangeLayer(self, event):
except ValueError:
try:
layer = list(self.mapDBInfo.layers.keys())[0]
except IndexError:
except (TypeError, IndexError, AttributeError):
return

if self.GetCurrentPage() == self.modifyPanel:
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/gui_core/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ def _filter(self, data):
try:
if re.compile(self.flt_pattern).search(dt):
flt_data.append(dt)
except re.error:
except (re.error, TypeError):
pass

return flt_data
Expand Down Expand Up @@ -1646,7 +1646,7 @@ def OnFilter(self, event):
try:
if re.compile(event.GetString()).search(layer):
list.append(layer)
except re.error:
except (re.error, TypeError):
pass
list = naturally_sorted(list)

Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gui_core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ def __init__(self, parent, giface, task, id=wx.ID_ANY, frame=None, *args, **kwar
# check wildcard
try:
fExt = os.path.splitext(p.get("key_desc", ["*.*"])[0])[1]
except IndexError:
except (TypeError, IndexError):
fExt = None
if not fExt:
fMask = "*"
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/gui_core/ghelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,15 +566,15 @@ def _langString(self, k, v):
allStr = "%s :" % k.upper()
try:
allStr += _(" %d translated") % v["good"]
except KeyError:
except (KeyError, TypeError):
pass
try:
allStr += _(" %d fuzzy") % v["fuzzy"]
except KeyError:
except (KeyError, TypeError):
pass
try:
allStr += _(" %d untranslated") % v["bad"]
except KeyError:
except (KeyError, TypeError):
pass
return allStr

Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gui_core/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ def _validate(self, win):
if text:
try:
datetime.strptime(text, "%Y-%m-%d")
except ValueError:
except (TypeError, ValueError):
self._notvalid()
return False

Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/iscatt/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def _renderscattplts(self, scatt_ids, cats, cats_attrs):
try:
self.cat_ids.remove(c)
scatt_dt[c]["render"] = True
except ValueError:
except (ValueError, KeyError):
scatt_dt[c]["render"] = False

if self.scatt_mgr.pol_sel_mode[0]:
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/iscatt/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def CursorPlotMove(self, x, y, scatt_id):
x = round(x)
y = round(y)
coords = True
except TypeError:
except (TypeError, ValueError):
coords = False

pane = self._getPane(scatt_id)
Expand Down
18 changes: 9 additions & 9 deletions gui/wxpython/location_wizard/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def OnSearch(self, event):
self.proj, self.projdesc = self.projlist.Search(
index=[0, 1], pattern=search_str
)
except:
except Exception:
self.proj = self.projdesc = ""

event.Skip()
Expand Down Expand Up @@ -1184,15 +1184,15 @@ def OnDText(self, event):
self.datumparams = self.parent.datums[self.datum][2]
try:
self.datumparams.remove("dx=0.0")
except:
except ValueError:
pass
try:
self.datumparams.remove("dy=0.0")
except:
except ValueError:
pass
try:
self.datumparams.remove("dz=0.0")
except:
except ValueError:
pass

nextButton.Enable(True)
Expand All @@ -1207,7 +1207,7 @@ def OnDSearch(self, event):
self.datum, self.ellipsoid, self.datumdesc = self.datumlist.Search(
index=[0, 1, 2], pattern=search_str
)
except:
except Exception:
self.datum = self.datumdesc = self.ellipsoid = ""

event.Skip()
Expand Down Expand Up @@ -1388,7 +1388,7 @@ def OnSearch(self, event):
self.ellipseparams = self.parent.ellipsoids[self.ellipse][1]
else:
self.ellipseparams = self.parent.planetary_ellipsoids[self.ellipse][1]
except:
except Exception:
self.ellipse = self.ellipsedesc = self.ellipseparams = ""

event.Skip()
Expand Down Expand Up @@ -1930,7 +1930,7 @@ def OnText(self, event):
self.epsgcode = event.GetString()
try:
self.epsgcode = int(self.epsgcode)
except:
except (TypeError, ValueError):
self.epsgcode = None

nextButton = wx.FindWindowById(wx.ID_FORWARD)
Expand Down Expand Up @@ -2555,7 +2555,7 @@ def __readData(self):
plist.append(p)
self.projections[proj.lower().strip()] = (projdesc.strip(), plist)
self.projdesc[proj.lower().strip()] = projdesc.strip()
except:
except Exception:
continue
f.close()

Expand Down Expand Up @@ -2617,7 +2617,7 @@ def __readData(self):
try:
pparam, datatype, proj4term, desc = line.split(":")
self.paramdesc[pparam] = (datatype, proj4term, desc)
except:
except ValueError:
continue
f.close()

Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/mapdisp/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def GetLayersFromCmdFile(self):
mapFile = line.split("=", 1)[1].strip()
try:
k, v = line[2:].strip().split("=", 1)
except:
except (ValueError, IndexError):
pass
render_env[k] = v
continue
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/mapwin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def HandlersCaller(self, event, handlers):
for handler in handlers:
try:
handler(event)
except:
except Exception:
handlers.remove(handler)
GError(
parent=self,
Expand Down Expand Up @@ -309,7 +309,7 @@ def UnregisterAllHandlers(self):
try:
handler("unregistered")
handlers.remove(handler)
except:
except Exception:
GError(
parent=self,
message=_(
Expand Down Expand Up @@ -348,7 +348,7 @@ def UnregisterMouseEventHandler(self, event, handler):
grass.warning(
_("Handler: %s was not registered") % handler.__name__
)
except:
except Exception:
GError(
parent=self,
message=_(
Expand Down
14 changes: 7 additions & 7 deletions gui/wxpython/mapwin/buffered.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ def _updateMFinished(self, renderVector=True):
for item in self.graphicsSetList:
try:
item.Draw()
except:
except Exception:
GError(
parent=self,
message=_(
Expand Down Expand Up @@ -1185,7 +1185,7 @@ def MouseDraw(self, pdc=None, begin=None, end=None):
r.Inflate(4, 4)
try:
pdc.ClearId(boxid)
except:
except Exception:
pass
self.RefreshRect(r, False)
pdc.SetId(boxid)
Expand All @@ -1202,7 +1202,7 @@ def MouseDraw(self, pdc=None, begin=None, end=None):
r.Inflate(4, 4)
try:
pdc.ClearId(self.lineid)
except:
except Exception:
pass
self.RefreshRect(r, False)
pdc.SetId(self.lineid)
Expand Down Expand Up @@ -1744,13 +1744,13 @@ def ClearLines(self, pdc=None):
try:
pdc.ClearId(self.lineid)
pdc.RemoveId(self.lineid)
except:
except Exception:
pass

try:
pdc.ClearId(self.plineid)
pdc.RemoveId(self.plineid)
except:
except Exception:
pass

Debug.msg(
Expand All @@ -1772,7 +1772,7 @@ def Pixel2Cell(self, xyCoords):
try:
x = int(xyCoords[0])
y = int(xyCoords[1])
except:
except (TypeError, ValueError, IndexError):
return None

if self.Map.region["ewres"] > self.Map.region["nsres"]:
Expand All @@ -1793,7 +1793,7 @@ def Cell2Pixel(self, enCoords):
try:
east = float(enCoords[0])
north = float(enCoords[1])
except:
except (TypeError, ValueError, IndexError):
return None

if self.Map.region["ewres"] > self.Map.region["nsres"]:
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/mapwin/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def _clearId(self, drawid):
"""Clears old object before drawing new object."""
try:
self.pdc.ClearId(drawid)
except:
except Exception:
pass


Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/modules/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def OnRun(self, event):
if nBandsStr:
try:
nBands = int(nBandsStr.rstrip("\n"))
except ValueError:
except (TypeError, ValueError):
pass
if nBands < 0:
GWarning(_("Unable to determine number of raster bands"), parent=self)
Expand Down
Loading
Loading