From 81cc70627c2734ff0c906c7dcd50311b5c21024f Mon Sep 17 00:00:00 2001 From: Arohan Ajit Date: Mon, 23 Sep 2024 15:15:04 +0000 Subject: [PATCH 1/4] fixed e722 --- gui/wxpython/core/gconsole.py | 2 +- gui/wxpython/core/render.py | 2 +- gui/wxpython/core/settings.py | 4 ++-- gui/wxpython/core/toolboxes.py | 2 +- gui/wxpython/core/utils.py | 10 +++++----- gui/wxpython/core/workspace.py | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/gui/wxpython/core/gconsole.py b/gui/wxpython/core/gconsole.py index bad4aac29cd..7575c401c98 100644 --- a/gui/wxpython/core/gconsole.py +++ b/gui/wxpython/core/gconsole.py @@ -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 diff --git a/gui/wxpython/core/render.py b/gui/wxpython/core/render.py index b98e4323578..5b3e3096043 100644 --- a/gui/wxpython/core/render.py +++ b/gui/wxpython/core/render.py @@ -1237,7 +1237,7 @@ def SetRegion(self, windres=False, windres3=False): return grass_region - except: + except Exception: return None def GetListOfLayers( diff --git a/gui/wxpython/core/settings.py b/gui/wxpython/core/settings.py index 45620220aed..2b2d3b28526 100644 --- a/gui/wxpython/core/settings.py +++ b/gui/wxpython/core/settings.py @@ -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"] @@ -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: diff --git a/gui/wxpython/core/toolboxes.py b/gui/wxpython/core/toolboxes.py index ae6b1b6a0a6..e77010ff213 100644 --- a/gui/wxpython/core/toolboxes.py +++ b/gui/wxpython/core/toolboxes.py @@ -209,7 +209,7 @@ def getMenudataFile(userRootFile, newFile, fallback): fh.write(xml) fh.close() return menudataFile - except: + except Exception: _debug( 2, ( diff --git a/gui/wxpython/core/utils.py b/gui/wxpython/core/utils.py index 10d6dca2759..4e73f10c112 100644 --- a/gui/wxpython/core/utils.py +++ b/gui/wxpython/core/utils.py @@ -77,7 +77,7 @@ def GetTempfile(pref=None): return os.path.join(pref, file) else: return tempfile - except: + except Exception: return None @@ -255,7 +255,7 @@ def ListOfCatsToRange(cats): try: cats = list(map(int, cats)) - except: + except ValueError: return catstr i = 0 @@ -579,7 +579,7 @@ def GetListOfLocations(dbase): os.path.join(location, "*") ): listOfLocations.append(os.path.basename(location)) - except: + except OSError: pass ListSortLower(listOfLocations) @@ -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 Exception: ret = None return _parseFormats(ret), _parseFormats(ret, writableOnly=True) @@ -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 Exception: ret = None return _parseFormats(ret), _parseFormats(ret, writableOnly=True) diff --git a/gui/wxpython/core/workspace.py b/gui/wxpython/core/workspace.py index 63f8b91cb89..9550aa73488 100644 --- a/gui/wxpython/core/workspace.py +++ b/gui/wxpython/core/workspace.py @@ -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") @@ -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 @@ -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): From 00f717fae7b62cae58b6fb54f6be4134203b02d6 Mon Sep 17 00:00:00 2001 From: Arohan Ajit Date: Mon, 23 Sep 2024 15:15:50 +0000 Subject: [PATCH 2/4] update flake8 --- .flake8 | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.flake8 b/.flake8 index 7092b7d15e3..af8a021bd4c 100644 --- a/.flake8 +++ b/.flake8 @@ -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 From 0d73aca4751ce1ca292c3086ec729c3cfada8237 Mon Sep 17 00:00:00 2001 From: Arohan Ajit Date: Mon, 23 Sep 2024 12:50:53 -0700 Subject: [PATCH 3/4] Update gui/wxpython/core/utils.py Co-authored-by: Vaclav Petras --- gui/wxpython/core/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/wxpython/core/utils.py b/gui/wxpython/core/utils.py index 4e73f10c112..facd82156d7 100644 --- a/gui/wxpython/core/utils.py +++ b/gui/wxpython/core/utils.py @@ -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 Exception: + except grass.CalledModuleError: ret = None return _parseFormats(ret), _parseFormats(ret, writableOnly=True) From bcfaaf871df5095003c3179080cadc07a29a3c78 Mon Sep 17 00:00:00 2001 From: Arohan Ajit Date: Mon, 23 Sep 2024 12:50:58 -0700 Subject: [PATCH 4/4] Update gui/wxpython/core/utils.py Co-authored-by: Vaclav Petras --- gui/wxpython/core/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/wxpython/core/utils.py b/gui/wxpython/core/utils.py index facd82156d7..4be6c18e2a2 100644 --- a/gui/wxpython/core/utils.py +++ b/gui/wxpython/core/utils.py @@ -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 Exception: + except grass.CalledModuleError: ret = None return _parseFormats(ret), _parseFormats(ret, writableOnly=True)