Skip to content

Commit

Permalink
checks: Replace bare except (Flake8 E722) in wxGUI/core (OSGeo#4367)
Browse files Browse the repository at this point in the history
This addresses the PEP8 style error E722 by specifying exception types in all bare except clauses found in wxGUI/core. Unclear cases use Exception.

---------

Co-authored-by: Vaclav Petras <wenzeslaus@gmail.com>
  • Loading branch information
arohanajit and wenzeslaus authored Sep 24, 2024
1 parent 16de4d3 commit 04cc9ea
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 19 deletions.
6 changes: 0 additions & 6 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +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/core/gconsole.py: E722
gui/wxpython/core/render.py: E722
gui/wxpython/core/settings.py: E722
gui/wxpython/core/toolboxes.py: E722
gui/wxpython/core/utils.py: E722
gui/wxpython/core/workspace.py: E722
gui/wxpython/datacatalog/tree.py: E731, E402
gui/wxpython/dbmgr/base.py: E722
gui/wxpython/dbmgr/dialogs.py: E722
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def load_source(modname, filename):
if len(command) == 1 and not skipInterface:
try:
task = gtask.parse_interface(command[0])
except:
except Exception:
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 @@ -1237,7 +1237,7 @@ def SetRegion(self, windres=False, windres3=False):

return grass_region

except:
except Exception:
return None

def GetListOfLayers(
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _generateLocale(self):
self.locs.sort()
# Add a default choice to not override system locale
self.locs.insert(0, "system")
except:
except Exception:
# No NLS
self.locs = ["system"]

Expand Down Expand Up @@ -992,7 +992,7 @@ def SaveToFile(self, settings=None):
if not os.path.exists(dirPath):
try:
os.mkdir(dirPath)
except:
except OSError:
GError(_("Unable to create settings directory"))
return
try:
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/toolboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def getMenudataFile(userRootFile, newFile, fallback):
fh.write(xml)
fh.close()
return menudataFile
except:
except Exception:
_debug(
2,
(
Expand Down
10 changes: 5 additions & 5 deletions gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def GetTempfile(pref=None):
return os.path.join(pref, file)
else:
return tempfile
except:
except Exception:
return None


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

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

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

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

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

return _parseFormats(ret), _parseFormats(ret, writableOnly=True)
Expand Down
6 changes: 3 additions & 3 deletions gui/wxpython/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __processFile(self):
try:
self.layerManager["pos"] = (posVal[0], posVal[1])
self.layerManager["size"] = (posVal[2], posVal[3])
except:
except IndexError:
pass
# current working directory
cwdPath = self.__getNodeText(node_lm, "cwd")
Expand Down Expand Up @@ -155,7 +155,7 @@ def __processFile(self):
try:
pos = (posVal[0], posVal[1])
size = (posVal[2], posVal[3])
except:
except IndexError:
pos = None
size = None
# this happens on Windows when mapwindow is minimized when
Expand Down Expand Up @@ -2019,7 +2019,7 @@ def _get_value(self, line):
"""Get value of element"""
try:
return line.strip(" ").split(" ")[1].strip(" ")
except:
except IndexError:
return ""

def _get_element(self, line):
Expand Down

0 comments on commit 04cc9ea

Please sign in to comment.