瀏覽代碼

pygrass: Remove usage of bare except (#1544)

* Plain try-finally is how re-raising is expressed according to the doc:
  'If there is a saved exception it is re-raised at the end of the finally clause.'
* datetime.strptime() produces ValueError.
* Only ImportError for import statement.
Vaclav Petras 4 年之前
父節點
當前提交
304a5ab420

+ 0 - 4
python/grass/pygrass/modules/interface/module.py

@@ -1035,8 +1035,6 @@ def run_modules_in_temp_region(module_list, q):
         for proc in module_list:
             proc.run()
             proc.wait()
-    except:
-        raise
     finally:
         q.put(module_list)
         del_temp_region()
@@ -1055,8 +1053,6 @@ def run_modules(module_list, q):
         for proc in module_list:
             proc.run()
             proc.wait()
-    except:
-        raise
     finally:
         q.put(module_list)
 

+ 1 - 1
python/grass/pygrass/raster/history.py

@@ -137,7 +137,7 @@ class History(object):
         if date_str:
             try:
                 return datetime.datetime.strptime(date_str, self.date_fmt)
-            except:
+            except ValueError:
                 return date_str
 
     def _set_date(self, datetimeobj):

+ 3 - 6
python/grass/pygrass/rpc/__init__.py

@@ -81,9 +81,8 @@ def _get_raster_image_as_np(lock, conn, data):
                 reg.adjust()
 
             array = raster2numpy_img(name, reg, color)
-    except:
-        raise
     finally:
+        # Send even if an exception was raised.
         conn.send(array)
 
 
@@ -120,9 +119,8 @@ def _get_vector_table_as_dict(lock, conn, data):
             ret = {}
             ret["table"] = table
             ret["columns"] = columns
-    except:
-        raise
     finally:
+        # Send even if an exception was raised.
         conn.send(ret)
 
 
@@ -171,9 +169,8 @@ def _get_vector_features_as_wkb_list(lock, conn, data):
                     bbox=bbox, feature_type=feature_type, field=field
                 )
             layer.close()
-    except:
-        raise
     finally:
+        # Send even if an exception was raised.
         conn.send(wkb_list)
 
 

+ 1 - 1
python/grass/pygrass/vector/abstract.py

@@ -182,7 +182,7 @@ class Info(object):
         date_str = utils.decode(libvect.Vect_get_map_date(self.c_mapinfo))
         try:
             return datetime.datetime.strptime(date_str, self.date_fmt)
-        except:
+        except ValueError:
             return date_str
 
     def _set_map_date(self, datetimeobj):

+ 1 - 1
python/grass/pygrass/vector/table.py

@@ -22,7 +22,7 @@ from sqlite3 import OperationalError
 
 try:
     from collections import OrderedDict
-except:
+except ImportError:
     from grass.pygrass.orderdict import OrderedDict
 
 import grass.lib.vector as libvect