Skip to content

Commit

Permalink
Checks: fix flake8 E741 remainder (OSGeo#3928)
Browse files Browse the repository at this point in the history
* Rename l to line when using `f.readlines()`.

* Remove "l"s from parameters since they aren't used.

* Rename "l" to "lx" to assign a lexer object.

* Add "# noqa: E741" as renaming parameters won't be applicable in this case.

* Rename "l" to "ln" as line number.

* Rename "l" to "layer" when looping through the layer list.

* Remove E741 for files in the 'locale', `python`, and `scripts` directory.

* Rename "ln" to "line_number".
  • Loading branch information
mshukuno authored and a0x8o committed Jul 23, 2024
1 parent 8b099b5 commit 35f705e
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 54 deletions.
14 changes: 5 additions & 9 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ per-file-ignores =
doc/python/vector_example_ctypes.py: F403, F405
doc/python/m.distance.py: F403, F405, E501
doc/gui/wxpython/example/dialogs.py: F401
locale/grass_po_stats.py: E122, E128, E231, E401, E722, E741
locale/grass_po_stats.py: E122, E128, E231, E401, E722
gui/scripts/d.wms.py: E501
gui/wxpython/core/gcmd.py: E402
gui/wxpython/core/gthread.py: F841
Expand Down Expand Up @@ -126,7 +126,6 @@ per-file-ignores =
python/grass/pygrass/vector/__init__.py: E402
python/grass/pygrass/modules/interface/*.py: F401
python/grass/pygrass/modules/grid/*.py: F401
python/grass/pygrass/raster/rowio.py: E741
python/grass/pygrass/raster/category.py: E721
python/grass/pygrass/rpc/__init__.py: F401, F403
python/grass/pygrass/utils.py: E402
Expand All @@ -136,13 +135,11 @@ per-file-ignores =
python/grass/temporal/datetime_math.py: F841, E722
python/grass/temporal/open_stds.py: F841
python/grass/temporal/spatial_topology_dataset_connector.py: E722
python/grass/temporal/temporal_algebra.py: E741, F841, E722
python/grass/temporal/temporal_algebra.py: F841, E722
python/grass/temporal/temporal_granularity.py: F841, E722
python/grass/temporal/temporal_raster_algebra.py: E741
python/grass/temporal/temporal_raster_base_algebra.py: F841, E722
python/grass/temporal/temporal_raster3d_algebra.py: E741
python/grass/temporal/temporal_topology_dataset_connector.py: E722
python/grass/temporal/temporal_vector_algebra.py: E741, F841
python/grass/temporal/temporal_vector_algebra.py: F841
python/grass/temporal/univar_statistics.py: E231
# Current benchmarks/tests are changing sys.path before import.
# Possibly, a different approach should be taken there anyway.
Expand All @@ -161,7 +158,7 @@ per-file-ignores =
# E402 module level import not at top of file
scripts/d.polar/d.polar.py: F841
scripts/r.in.wms/wms_gdal_drv.py: F841, E722
scripts/r.in.wms/wms_cap_parsers.py: F841, E741
scripts/r.in.wms/wms_cap_parsers.py: F841
scripts/r.in.wms/wms_drv.py: E402, E722
scripts/r.in.wms/srs.py: E722
scripts/r.semantic.label/r.semantic.label.py: F841, E501
Expand All @@ -170,8 +167,7 @@ per-file-ignores =
scripts/g.extension/g.extension.py: F841, E722, E501
scripts/v.unpack/v.unpack.py: F841, E722, E501
scripts/v.import/v.import.py: F841, E722, E501
scripts/db.univar/db.univar.py: E741, E501
scripts/d.rast.leg/d.rast.leg.py: E741
scripts/db.univar/db.univar.py: E501
scripts/d.frame/d.frame.py: E722
scripts/i.pansharpen/i.pansharpen.py: E722, E501
scripts/r.in.srtm/r.in.srtm.py: E722
Expand Down
8 changes: 4 additions & 4 deletions locale/grass_po_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def read_msgfmt_statistics(msg, lgood, lfuzzy, lbad):

def langDefinition(fil):
f = codecs.open(fil, encoding="utf-8", errors="replace", mode="r")
for l in f.readlines():
if '"Language-Team:' in l:
lang = l.split(" ")[1:-1]
for line in f.readlines():
if '"Language-Team:' in line:
lang = line.split(" ")[1:-1]
break
f.close()
if len(lang) == 2:
Expand Down Expand Up @@ -136,7 +136,7 @@ def writejson(stats, outfile):
# load dictionary into json format
fjson = json.dumps(stats, sort_keys=True, indent=4)
# write a string with pretty style
outjson = os.linesep.join([l.rstrip() for l in fjson.splitlines()])
outjson = os.linesep.join([line.rstrip() for line in fjson.splitlines()])
# write out file
fout = open(outfile, "w")
fout.write(outjson)
Expand Down
6 changes: 3 additions & 3 deletions python/grass/pygrass/raster/rowio.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
)


def getmaprow_CELL(fd, buf, row, l):
def getmaprow_CELL(fd, buf, row):
librast.Rast_get_c_row(fd, ctypes.cast(buf, ctypes.POINTER(librast.CELL)), row)
return 1


def getmaprow_FCELL(fd, buf, row, l):
def getmaprow_FCELL(fd, buf, row):
librast.Rast_get_f_row(fd, ctypes.cast(buf, ctypes.POINTER(librast.FCELL)), row)
return 1


def getmaprow_DCELL(fd, buf, row, l):
def getmaprow_DCELL(fd, buf, row):
librast.Rast_get_d_row(fd, ctypes.cast(buf, ctypes.POINTER(librast.DCELL)), row)
return 1

Expand Down
12 changes: 6 additions & 6 deletions python/grass/temporal/temporal_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ def setup_common_granularity(self, expression, stdstype="strds", lexer=None):
:return: True if successful, False otherwise
"""
l = lexer
lx = lexer
# Split the expression to ignore the left part
expressions = expression.split("=")[1:]
expression = " ".join(expressions)
Expand All @@ -895,17 +895,17 @@ def setup_common_granularity(self, expression, stdstype="strds", lexer=None):
return False

# detect all STDS
if l is None:
l = TemporalAlgebraLexer()
l.build()
l.lexer.input(expression)
if lx is None:
lx = TemporalAlgebraLexer()
lx.build()
lx.lexer.input(expression)

name_list = []
tokens = []

count = 0
while True:
tok = l.lexer.token()
tok = lx.lexer.token()
if not tok:
break

Expand Down
8 changes: 4 additions & 4 deletions python/grass/temporal/temporal_raster3d_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ def __init__(

def parse(self, expression, basename=None, overwrite=False):
# Check for space time dataset type definitions from temporal algebra
l = TemporalRasterAlgebraLexer()
l.build()
l.lexer.input(expression)
lx = TemporalRasterAlgebraLexer()
lx.build()
lx.lexer.input(expression)

while True:
tok = l.lexer.token()
tok = lx.lexer.token()
if not tok:
break

Expand Down
8 changes: 4 additions & 4 deletions python/grass/temporal/temporal_raster_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ def __init__(

def parse(self, expression, basename=None, overwrite=False):
# Check for space time dataset type definitions from temporal algebra
l = TemporalRasterAlgebraLexer()
l.build()
l.lexer.input(expression)
lx = TemporalRasterAlgebraLexer()
lx.build()
lx.lexer.input(expression)

while True:
tok = l.lexer.token()
tok = lx.lexer.token()
if not tok:
break

Expand Down
8 changes: 4 additions & 4 deletions python/grass/temporal/temporal_vector_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ def __init__(self, pid=None, run=False, debug=True, spatial=False):

def parse(self, expression, basename=None, overwrite=False):
# Check for space time dataset type definitions from temporal algebra
l = TemporalVectorAlgebraLexer()
l.build()
l.lexer.input(expression)
lx = TemporalVectorAlgebraLexer()
lx.build()
lx.lexer.input(expression)

while True:
tok = l.lexer.token()
tok = lx.lexer.token()
if not tok:
break

Expand Down
2 changes: 1 addition & 1 deletion scripts/d.rast.leg/d.rast.leg.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
import grass.script as grass


def make_frame(f, b, t, l, r):
def make_frame(f, b, t, l, r): # noqa: E741
(fl, fr, ft, fb) = f

t /= 100.0
Expand Down
14 changes: 7 additions & 7 deletions scripts/db.univar/db.univar.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,23 +313,23 @@ def main():
pval[i] = 0

inf = open(tmp + ".sort")
l = 1
line_number = 1
for line in inf:
line = line.rstrip("\r\n")
if len(line) == 0:
continue
if l == q25pos:
if line_number == q25pos:
q25 = float(line)
if l == q50apos:
if line_number == q50apos:
q50a = float(line)
if l == q50bpos:
if line_number == q50bpos:
q50b = float(line)
if l == q75pos:
if line_number == q75pos:
q75 = float(line)
for i in range(len(ppos)):
if l == ppos[i]:
if line_number == ppos[i]:
pval[i] = float(line)
l += 1
line_number += 1

q50 = (q50a + q50b) / 2

Expand Down
24 changes: 12 additions & 12 deletions scripts/r.in.wms/wms_cap_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ def _checkLayerTree(self, parent_layer, first=True):

layers = parent_layer.findall(self.xml_ns.Ns("Layer"))

for l in layers:
self._initLayer(l, parent_layer)
self._checkLayerTree(l, False)
for layer in layers:
self._initLayer(layer, parent_layer)
self._checkLayerTree(layer, False)

def _initLayer(self, layer, parent_layer):
"""Inherit elements from parent layer
Expand Down Expand Up @@ -340,10 +340,10 @@ def __init__(self, cap_file):
self._findall(contents, "TileMatrixSet", self.xml_ns.NsWmts)

layers = self._findall(contents, "Layer", self.xml_ns.NsWmts)
for l in layers:
if not self._checkLayer(l):
for layer in layers:
if not self._checkLayer(layer):
grass.debug("Removed invalid <Layer> element.", 4)
contents.remove(l)
contents.remove(layer)

# are there any <Layer> elements after the check
self._findall(contents, "Layer", self.xml_ns.NsWmts)
Expand Down Expand Up @@ -580,12 +580,12 @@ def _checkLayerTree(self, parent_layer, first=True):
layers = parent_layer.findall("TiledGroup")
layers += parent_layer.findall("TiledGroups")

for l in layers:
if not self._checkLayer(l):
grass.debug(("Removed invalid <%s> element." % l.tag), 4)
parent_layer.remove(l)
if l.tag == "TiledGroups":
self._checkLayerTree(l, False)
for layer in layers:
if not self._checkLayer(layer):
grass.debug(("Removed invalid <%s> element." % layer.tag), 4)
parent_layer.remove(layer)
if layer.tag == "TiledGroups":
self._checkLayerTree(layer, False)

def _find(self, etreeElement, tag):
"""!Find child element.
Expand Down

0 comments on commit 35f705e

Please sign in to comment.