Skip to content

Commit

Permalink
style: Fix pylint try-except-raise (W0706) (OSGeo#3997)
Browse files Browse the repository at this point in the history
* python(grass.temporal): Fix pylint try-except-raise (W0706)

Do not catch exception only to raise it again

* gui/wxpython/core/utils: Fix pylint try-except-raise (W0706)

* python: Fix pylint try-except-raise (W0706)

* style: Enable ruff useless-try-except (TRY302) as fixed
  • Loading branch information
echoix authored Jul 9, 2024
1 parent 2f5bed6 commit 4be87a1
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 48 deletions.
19 changes: 8 additions & 11 deletions gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,17 +572,14 @@ def GetListOfLocations(dbase):
"""
listOfLocations = []

try:
for location in glob.glob(os.path.join(dbase, "*")):
try:
if os.path.join(location, "PERMANENT") in glob.glob(
os.path.join(location, "*")
):
listOfLocations.append(os.path.basename(location))
except:
pass
except (UnicodeEncodeError, UnicodeDecodeError) as e:
raise e
for location in glob.glob(os.path.join(dbase, "*")):
try:
if os.path.join(location, "PERMANENT") in glob.glob(
os.path.join(location, "*")
):
listOfLocations.append(os.path.basename(location))
except:
pass

ListSortLower(listOfLocations)

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ ignore = [
"TRY201", # verbose-raise
"TRY300", # try-consider-else
"TRY301", # raise-within-try
"TRY302", # useless-try-except
"UP015", # redundant-open-modes
"UP018", # native-literals
"UP030", # format-literals
Expand Down
2 changes: 0 additions & 2 deletions python/grass/imaging/images2swf.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,6 @@ def writeSwf(filename, images, duration=0.1, repeat=True):
fp = open(filename, "wb")
try:
buildFile(fp, taglist, nframes=nframes, framesize=wh, fps=fps)
except Exception:
raise
finally:
fp.close()

Expand Down
26 changes: 0 additions & 26 deletions python/grass/temporal/c_libraries_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ def _read_map_full_info(lock, conn, data):
info = _read_raster_full_info(name, mapset)
elif maptype == RPCDefs.TYPE_VECTOR:
info = _read_vector_full_info(name, mapset)
except:
raise
finally:
conn.send(info)

Expand Down Expand Up @@ -295,8 +293,6 @@ def _get_database_name(lock, conn, data):
dbstring = dbstring.replace(encode("$GISDBASE"), libgis.G_gisdbase())
dbstring = dbstring.replace(encode("$LOCATION_NAME"), libgis.G_location())
dbstring = dbstring.replace(encode("$MAPSET"), mapset)
except:
raise
finally:
conn.send(decode(dbstring))

Expand Down Expand Up @@ -353,8 +349,6 @@ def _available_mapsets(lock, conn, data):
mapset_list.reverse()
mapset_list.append(current_mapset)
mapset_list.reverse()
except:
raise
finally:
conn.send(mapset_list)

Expand Down Expand Up @@ -387,8 +381,6 @@ def _has_timestamp(lock, conn, data):
elif maptype == RPCDefs.TYPE_RASTER3D:
if libgis.G_has_raster3d_timestamp(name, mapset) == 1:
check = True
except:
raise
finally:
conn.send(check)

Expand Down Expand Up @@ -437,8 +429,6 @@ def _read_timestamp(lock, conn, data):
check = libgis.G_read_raster3d_timestamp(name, mapset, byref(ts))

dates = _convert_timestamp_from_grass(ts)
except:
raise
finally:
conn.send((check, dates))

Expand Down Expand Up @@ -483,8 +473,6 @@ def _write_timestamp(lock, conn, data):
check = libgis.G_write_vector_timestamp(name, layer, byref(ts))
elif maptype == RPCDefs.TYPE_RASTER3D:
check = libgis.G_write_raster3d_timestamp(name, byref(ts))
except:
raise
finally:
conn.send(check)

Expand Down Expand Up @@ -520,8 +508,6 @@ def _remove_timestamp(lock, conn, data):
check = libgis.G_remove_vector_timestamp(name, layer, mapset)
elif maptype == RPCDefs.TYPE_RASTER3D:
check = libgis.G_remove_raster3d_timestamp(name, mapset)
except:
raise
finally:
conn.send(check)

Expand Down Expand Up @@ -561,8 +547,6 @@ def _read_semantic_label(lock, conn, data):
maptype=maptype,
)
return -1
except:
raise
finally:
conn.send(semantic_label)

Expand Down Expand Up @@ -599,8 +583,6 @@ def _write_semantic_label(lock, conn, data):
maptype=maptype,
)
return -2
except:
raise
finally:
conn.send(True)

Expand Down Expand Up @@ -634,8 +616,6 @@ def _remove_semantic_label(lock, conn, data):
maptype=maptype,
)
return -2
except:
raise
finally:
conn.send(check)

Expand Down Expand Up @@ -668,8 +648,6 @@ def _map_exists(lock, conn, data):

if mapset:
check = True
except:
raise
finally:
conn.send(check)

Expand All @@ -696,8 +674,6 @@ def _read_map_info(lock, conn, data):
kvp = _read_vector_info(name, mapset)
elif maptype == RPCDefs.TYPE_RASTER3D:
kvp = _read_raster3d_info(name, mapset)
except:
raise
finally:
conn.send(kvp)

Expand Down Expand Up @@ -1006,8 +982,6 @@ def _read_map_history(lock, conn, data):
kvp = _read_vector_history(name, mapset)
elif maptype == RPCDefs.TYPE_RASTER3D:
kvp = _read_raster3d_history(name, mapset)
except:
raise
finally:
conn.send(kvp)

Expand Down
10 changes: 2 additions & 8 deletions python/grass/temporal/datetime_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,7 @@ def modify_datetime(
if residual_months == 0:
residual_months = 1

try:
dt1 = dt1.replace(year=year + years_to_add, month=residual_months)
except:
raise
dt1 = dt1.replace(year=year + years_to_add, month=residual_months)

tdelta_months = dt1 - mydate
elif months < 0:
Expand All @@ -350,10 +347,7 @@ def modify_datetime(
if residual_months <= 0:
residual_months += 12

try:
dt1 = dt1.replace(year=year - years_to_remove, month=residual_months)
except:
raise
dt1 = dt1.replace(year=year - years_to_remove, month=residual_months)

tdelta_months = dt1 - mydate

Expand Down

0 comments on commit 4be87a1

Please sign in to comment.