Pārlūkot izejas kodu

scripts: Remove unused vars or ignore in Flake8 (#1498)

* Remove unused variables.
* Use one previously unused exception for an error message.
* Ignore the unclear cases using per-file-ignores (to be resolved in the future).
Vaclav Petras 4 gadi atpakaļ
vecāks
revīzija
d7a56b30f3

+ 13 - 1
scripts/.flake8

@@ -5,9 +5,21 @@ ignore =
     E402, # module level import not at top of file
     E722, # do not use bare 'except'
     E741, # ambiguous variable name 'l'
-    F841, # local variable 'center' is assigned to but never used
     E501, # line too long (161 > 150 characters)
 
+per-file-ignores =
+    # Many of these ignores can and should be removed and the problem fixed.
+    # F841 local variable is assigned to but never used
+    d.polar/d.polar.py: F841
+    r.in.wms/wms_gdal_drv.py: F841
+    r.in.wms/wms_cap_parsers.py: F841
+    i.band/i.band.py: F841
+    v.report/v.report.py: F841
+    db.out.ogr/db.out.ogr.py: F841
+    g.extension/g.extension.py: F841
+    v.unpack/v.unpack.py: F841
+    v.import/v.import.py: F841
+
 max-line-length = 88
 exclude =
     .git,

+ 1 - 1
scripts/d.rast.edit/d.rast.edit.py

@@ -405,7 +405,7 @@ def wxGUI():
             sizer = wx.BoxSizer(orient=wx.VERTICAL)
 
             self.canvas = Canvas(app, parent=self)
-            si = sizer.Add(self.canvas, proportion=1, flag=wx.EXPAND)
+            sizer.Add(self.canvas, proportion=1, flag=wx.EXPAND)
 
             tools = wx.BoxSizer(wx.HORIZONTAL)
 

+ 0 - 1
scripts/g.bands/g.bands.py

@@ -51,7 +51,6 @@ import grass.script as gs
 def main():
     from grass.bandref import BandReferenceReader, BandReferenceReaderError
 
-    band = None
     kwargs = {}
     if "," in options["pattern"]:
         gs.fatal("Multiple values not supported")

+ 6 - 2
scripts/g.extension/g.extension.py

@@ -1175,8 +1175,12 @@ def install_module_xml(mlist):
             desc = gtask.parse_interface(name).description
             # mname = gtask.parse_interface(name).name
             keywords = gtask.parse_interface(name).keywords
-        except Exception as e:
-            grass.warning(_("No metadata available for module '%s'.") % name)
+        except Exception as error:
+            grass.warning(
+                _("No metadata available for module '{name}': {error}").format(
+                    name=name, error=error
+                )
+            )
             continue
 
         tnode = None

+ 0 - 1
scripts/i.pansharpen/i.pansharpen.py

@@ -605,7 +605,6 @@ def pca(pan, ms1, ms2, ms3, out, pid, sproc):
         b3evect.append(float(l.split(",")[3]))
 
     # inverse PCA with hi res pan channel substituted for principal component 1
-    pca1 = "tmp%s.pca.1" % pid
     pca2 = "tmp%s.pca.2" % pid
     pca3 = "tmp%s.pca.3" % pid
     b1evect1 = b1evect[0]

+ 2 - 2
scripts/r.fillnulls/r.fillnulls.py

@@ -611,7 +611,7 @@ def main():
                         )
                         % (input,)
                     )
-            except CalledModuleError as e:
+            except CalledModuleError:
                 grass.fatal(
                     _("Failure during bspline interpolation. Error message: %s")
                     % stderr
@@ -643,7 +643,7 @@ def main():
                         )
                         % (input,)
                     )
-            except CalledModuleError as e:
+            except CalledModuleError:
                 grass.fatal(
                     _("Failure during bspline interpolation. Error message: %s")
                     % stderr

+ 1 - 1
scripts/r.import/r.import.py

@@ -206,7 +206,7 @@ def main():
                 % GDALdatasource
             )
             return 0
-        except CalledModuleError as e:
+        except CalledModuleError:
             grass.fatal(_("Unable to import GDAL dataset <%s>") % GDALdatasource)
 
     grassenv = grass.gisenv()

+ 0 - 1
scripts/r.in.wms/wms_drv.py

@@ -1007,7 +1007,6 @@ class OnEarthRequestMgr(BaseRequestMgr):
             if best_patt is None:
                 best_res = t_res[comp_res]
                 best_patt = pattern
-                first = False
                 continue
 
             best_diff = best_res - res[comp_res]

+ 0 - 4
scripts/v.dissolve/v.dissolve.py

@@ -96,10 +96,6 @@ def main():
         if coltype["type"] not in ("INTEGER", "SMALLINT", "CHARACTER", "TEXT"):
             grass.fatal(_("Key column must be of type integer or string"))
 
-        f = grass.vector_layer_db(input, layer)
-
-        table = f["table"]
-
         tmpfile = "%s_%s" % (output, tmp)
 
         try:

+ 0 - 2
scripts/v.in.lines/v.in.lines.py

@@ -51,8 +51,6 @@ def main():
     fs = separator(options["separator"])
     threeD = flags["z"]
 
-    prog = "v.in.lines"
-
     if threeD:
         do3D = "z"
     else:

+ 0 - 2
scripts/v.in.mapgen/v.in.mapgen.py

@@ -70,8 +70,6 @@ def main():
 
     prog = "v.in.mapgen"
 
-    opts = ""
-
     if not os.path.isfile(infile):
         grass.fatal(_("Input file <%s> not found") % infile)