Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Fix unnecessary-comprehension (C416) #4453

Merged
merged 4 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions gui/wxpython/lmgr/giface.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(self, tree):
self._tree = tree

def __len__(self):
return len([layer for layer in self])
return len(list(self))

def __iter__(self):
"""Iterates over the contents of the list."""
Expand All @@ -66,11 +66,11 @@ def __iter__(self):

def __getitem__(self, index):
"""Select a layer from the LayerList using the index."""
return [layer for layer in self][index]
return list(self)[index]

def __repr__(self):
"""Return a representation of the object."""
return "LayerList(%r)" % [layer for layer in self]
return "LayerList(%r)" % list(self)

def GetSelectedLayers(self, checkedOnly=True):
items = self._tree.GetSelectedLayer(multi=True, checkedOnly=checkedOnly)
Expand Down
9 changes: 3 additions & 6 deletions gui/wxpython/timeline/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,9 @@ def _checkDatasets(self, datasets):
if allDatasets:
allDatasets = reduce(add, reduce(add, allDatasets))
mapsets = tgis.get_tgis_c_library_interface().available_mapsets()
allDatasets = [
i
for i in sorted(
allDatasets, key=lambda dataset_info: mapsets.index(dataset_info[1])
)
]
allDatasets = sorted(
allDatasets, key=lambda dataset_info: mapsets.index(dataset_info[1])
)

for dataset in datasets:
errorMsg = _("Space time dataset <%s> not found.") % dataset
Expand Down
9 changes: 3 additions & 6 deletions gui/wxpython/tplot/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,12 +1156,9 @@ def _checkDatasets(self, datasets, typ):
if allDatasets:
allDatasets = reduce(add, reduce(add, allDatasets))
mapsets = tgis.get_tgis_c_library_interface().available_mapsets()
allDatasets = [
i
for i in sorted(
allDatasets, key=lambda dataset_info: mapsets.index(dataset_info[1])
)
]
allDatasets = sorted(
allDatasets, key=lambda dataset_info: mapsets.index(dataset_info[1])
)

for dataset in datasets:
errorMsg = _("Space time dataset <%s> not found.") % dataset
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/web_services/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def UpdateWidgetsByCmd(self, cmd):

# WMS standard - first layer in params is most bottom...
# therefore layers order need to be reversed
l_st_list = [layer for layer in reversed(l_st_list)]
l_st_list.reverse()
self.list.SelectLayers(l_st_list)

params = {}
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ ignore = [
"BLE001", # blind-except
"C404", # unnecessary-list-comprehension-dict
"C414", # unnecessary-double-cast-or-process
"C416", # unnecessary-comprehension
"COM812", # missing-trailing-comma
"COM818", # trailing-comma-on-bare-tuple
"D1",
Expand Down
4 changes: 2 additions & 2 deletions python/grass/imaging/images2gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def handleSubRectangles(self, images, subRectangles):
xy = (0, 0)
if hasattr(xy, "__len__"):
if len(xy) == len(images):
xy = [xxyy for xxyy in xy]
xy = list(xy)
else:
raise ValueError("len(xy) doesn't match amount of images.")
else:
Expand Down Expand Up @@ -594,7 +594,7 @@ def writeGifVisvis(
# Check duration
if hasattr(duration, "__len__"):
if len(duration) == len(images):
duration = [d for d in duration]
duration = list(duration)
else:
raise ValueError("len(duration) doesn't match amount of images.")
else:
Expand Down
2 changes: 1 addition & 1 deletion python/grass/imaging/images2swf.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ def writeSwf(filename, images, duration=0.1, repeat=True):
# Check duration
if hasattr(duration, "__len__"):
if len(duration) == len(images2):
duration = [d for d in duration]
duration = list(duration)
else:
raise ValueError("len(duration) doesn't match amount of images.")
else:
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/gis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def mapsets(self, pattern=None, permissions=True):
[...]

"""
mapsets = [mapset for mapset in self]
mapsets = list(self)
if permissions:
mapsets = [
mapset
Expand Down
12 changes: 6 additions & 6 deletions python/grass/pygrass/modules/grid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def get_mapset(gisrc_src, gisrc_dst):
copy_special_mapset_files(path_src, path_dst)
src = Mapset(msrc, lsrc, gsrc)
dst = Mapset(mdst, ldst, gdst)
visible = [m for m in src.visible]
visible = list(src.visible)
if src.name not in visible:
visible.append(src.name)
dst.visible.extend(visible)
Expand Down Expand Up @@ -189,7 +189,7 @@ def rmloc(r):
# change gisdbase to src
env["GISRC"] = gisrc_src
get_grp(group=grp, env_=env)
rasts = [r for r in get_grp.outputs.stdout.split()]
rasts = list(get_grp.outputs.stdout.split())
# change gisdbase to dst
env["GISRC"] = gisrc_dst
rast2cp = [r for r in rasts if rmloc(r) not in all_rasts]
Expand Down Expand Up @@ -497,15 +497,15 @@ def __init__(
self.gisrc_dst = write_gisrc(
self.n_mset.gisdbase, self.n_mset.location, self.n_mset.name
)
rasters = [r for r in select(self.module.inputs, "raster")]
rasters = list(select(self.module.inputs, "raster"))
if rasters:
copy_rasters(
rasters, self.gisrc_src, self.gisrc_dst, region=self.region
)
vectors = [v for v in select(self.module.inputs, "vector")]
vectors = list(select(self.module.inputs, "vector"))
if vectors:
copy_vectors(vectors, self.gisrc_src, self.gisrc_dst)
groups = [g for g in select(self.module.inputs, "group")]
groups = list(select(self.module.inputs, "group"))
if groups:
copy_groups(groups, self.gisrc_src, self.gisrc_dst, region=self.region)
self.bboxes = split_region_in_overlapping_tiles(
Expand Down Expand Up @@ -592,7 +592,7 @@ def get_works(self):
else:
ldst, gdst = self.mset.location, self.mset.gisdbase
cmd = self.module.get_dict()
groups = [g for g in select(self.module.inputs, "group")]
groups = list(select(self.module.inputs, "group"))
for row, box_row in enumerate(self.bboxes):
for col, box in enumerate(box_row):
inms = None
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/vector/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def __iter__(self):
return (self.c_ilist.contents.value[i] for i in range(self.__len__()))

def __repr__(self):
return "Ilist(%r)" % [i for i in self.__iter__()]
return "Ilist(%r)" % list(self.__iter__())

def __contains__(self, item):
return item in self.__iter__()
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/vector/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ def __getitem__(self, item):
return self.by_name(item)

def __repr__(self):
return "DBlinks(%r)" % [link for link in self.__iter__()]
return "DBlinks(%r)" % list(self.__iter__())

def by_index(self, indx):
"""Return a Link object by index
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/vector/testsuite/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_table_random_values(nrows, columns):
raise TypeError("Unknown column type %s for: %s" % (ctype, cname))
vals.append(COL2VALS[ctype](nrows))
dtype.append((cname, vals[-1].dtype.str))
return np.array([v for v in zip(*vals)], dtype=dtype)
return np.array(list(zip(*vals)), dtype=dtype)


class DBconnection:
Expand Down
4 changes: 1 addition & 3 deletions scripts/i.oif/i.oif.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ def main():

grass.message(_("Calculating Correlation Matrix..."))
correlation = {}
s = grass.read_command(
"r.covar", flags="r", map=[band for band in bands], quiet=True
)
s = grass.read_command("r.covar", flags="r", map=list(bands), quiet=True)

# We need to skip the first line, since r.covar prints the number of values
lines = s.splitlines()
Expand Down
Loading