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 readlines-in-for (FURB129) #4034

Merged
merged 1 commit into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def RunCmd(
if os.path.splitext(command[0])[1] in {".py", ".sh"}:
try:
with open(command[0], "r") as sfile:
for line in sfile.readlines():
for line in sfile:
if len(line) < 3:
continue
if line.startswith(("#%", "# %")):
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ def GetWindow(self):
% {"file": filename, "ret": e}
)

for line in windfile.readlines():
for line in windfile:
line = line.strip()
try:
key, value = line.split(":", 1)
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ def _readLegacyFile(self, settings=None):

try:
line = ""
for line in fd.readlines():
for line in fd:
line = line.rstrip("%s" % os.linesep)
group, key = line.split(self.sep)[0:2]
kv = line.split(self.sep)[2:]
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ def StoreEnvVariable(key, value=None, envFile=None):
except OSError as e:
sys.stderr.write(_("Unable to open file '%s'\n") % envFile)
return
for line in fd.readlines():
for line in fd:
line = line.rstrip(os.linesep)
try:
k, v = (x.strip() for x in line.split(" ", 1)[1].split("=", 1))
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def on_modified(self, event):
time.sleep(0.1)
with open(event.src_path, "r") as f:
gisrc = {}
for line in f.readlines():
for line in f:
key, val = line.split(":")
gisrc[key.strip()] = val.strip()
new = os.path.join(
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ def read(self, parent):
return []

line_id = 1
for line in file.readlines():
for line in file:
self.process_line(line.rstrip("\n"), line_id)
line_id += 1

Expand Down
10 changes: 5 additions & 5 deletions gui/wxpython/gcp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __init__(self, parent, giface):
self.gisrc_dict = {}
try:
f = open(self.target_gisrc, "r")
for line in f.readlines():
for line in f:
line = line.replace("\n", "").strip()
if len(line) < 1:
continue
Expand Down Expand Up @@ -978,7 +978,7 @@ def OnEnterPage(self, event=None):

try:
with open(vgrpfile) as f:
for vect in f.readlines():
for vect in f:
vect = vect.strip("\n")
if len(vect) < 1:
continue
Expand Down Expand Up @@ -1616,7 +1616,7 @@ def ReadGCPs(self):
f = open(self.file["points"], "r")
GCPcnt = 0

for line in f.readlines():
for line in f:
if line[0] == "#" or line == "":
continue
line = line.replace("\n", "").strip()
Expand Down Expand Up @@ -1868,7 +1868,7 @@ def OnGeorect(self, event):
f = open(self.file["vgrp"])
vectlist = []
try:
for vect in f.readlines():
for vect in f:
vect = vect.strip("\n")
if len(vect) < 1:
continue
Expand Down Expand Up @@ -2736,7 +2736,7 @@ def __init__(
f = open(self.vgrpfile)
try:
checked = []
for line in f.readlines():
for line in f:
line = line.replace("\n", "")
if len(line) < 1:
continue
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gui_core/ghelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ def fillContentsFromFile(self, htmlFile, skipDescription=True):
try:
contents = []
skip = False
for line in open(htmlFile, "rb").readlines():
for line in open(htmlFile, "rb"):
if "DESCRIPTION" in line:
skip = False
if not skip:
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/image2target/ii2t_gis_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def _readGisRC(self):
if gisrc and os.path.isfile(gisrc):
try:
rc = open(gisrc, "r")
for line in rc.readlines():
for line in rc:
try:
key, val = line.split(":", 1)
except ValueError as e:
Expand Down
10 changes: 5 additions & 5 deletions gui/wxpython/image2target/ii2t_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __init__(self, parent, giface):
self.gisrc_dict = {}
try:
f = open(self.target_gisrc, "r")
for line in f.readlines():
for line in f:
line = line.replace("\n", "").strip()
if len(line) < 1:
continue
Expand Down Expand Up @@ -974,7 +974,7 @@ def OnEnterPage(self, event=None):

f = open(vgrpfile)
try:
for vect in f.readlines():
for vect in f:
vect = vect.strip("\n")
if len(vect) < 1:
continue
Expand Down Expand Up @@ -1640,7 +1640,7 @@ def ReadGCPs(self):
f = open(self.file["control_points"], "r")
GCPcnt = 0

for line in f.readlines():
for line in f:
if line[0] == "#" or line == "":
continue
line = line.replace("\n", "").strip()
Expand Down Expand Up @@ -1821,7 +1821,7 @@ def OnGeorect(self, event):
f = open(self.file["vgrp"])
vectlist = []
try:
for vect in f.readlines():
for vect in f:
vect = vect.strip("\n")
if len(vect) < 1:
continue
Expand Down Expand Up @@ -2682,7 +2682,7 @@ def __init__(
f = open(self.vgrpfile)
try:
checked = []
for line in f.readlines():
for line in f:
line = line.replace("\n", "")
if len(line) < 1:
continue
Expand Down
10 changes: 5 additions & 5 deletions gui/wxpython/location_wizard/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2563,7 +2563,7 @@ def __readData(self):
f = open(os.path.join(globalvar.ETCDIR, "proj", "parms.table"), "r")
self.projections = {}
self.projdesc = {}
for line in f.readlines():
for line in f:
line = line.strip()
try:
proj, projdesc, params = line.split(":")
Expand All @@ -2586,7 +2586,7 @@ def __readData(self):
f = open(os.path.join(globalvar.ETCDIR, "proj", "datum.table"), "r")
self.datums = {}
paramslist = []
for line in f.readlines():
for line in f:
line = line.expandtabs(1)
line = line.strip()
if line == "" or line[0] == "#":
Expand All @@ -2603,7 +2603,7 @@ def __readData(self):
# read Earth-based ellipsiod definitions
f = open(os.path.join(globalvar.ETCDIR, "proj", "ellipse.table"), "r")
self.ellipsoids = {}
for line in f.readlines():
for line in f:
line = line.expandtabs(1)
line = line.strip()
if line == "" or line[0] == "#":
Expand All @@ -2621,7 +2621,7 @@ def __readData(self):
os.path.join(globalvar.ETCDIR, "proj", "ellipse.table.solar.system"), "r"
)
self.planetary_ellipsoids = {}
for line in f.readlines():
for line in f:
line = line.expandtabs(1)
line = line.strip()
if line == "" or line[0] == "#":
Expand All @@ -2637,7 +2637,7 @@ def __readData(self):
# read projection parameter description and parsing table
f = open(os.path.join(globalvar.ETCDIR, "proj", "desc.table"), "r")
self.paramdesc = {}
for line in f.readlines():
for line in f:
line = line.strip()
try:
pparam, datatype, proj4term, desc = line.split(":")
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/photo2image/ip2i_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __init__(
self.gisrc_dict = {}
try:
f = open(self.target_gisrc, "r")
for line in f.readlines():
for line in f:
line = line.replace("\n", "").strip()
if len(line) < 1:
continue
Expand Down Expand Up @@ -963,7 +963,7 @@ def ReadGCPs(self):
f = open(self.file["points"], "r")
GCPcnt = 0

for line in f.readlines():
for line in f:
if line[0] == "#" or line == "":
continue
line = line.replace("\n", "").strip()
Expand Down
4 changes: 2 additions & 2 deletions gui/wxpython/vnet/vnet_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def GetLastModified(self):
)
try:
head = open(headPath, "r")
for line in head.readlines():
for line in head:
i = line.find(
"MAP DATE:",
)
Expand Down Expand Up @@ -1299,7 +1299,7 @@ def _getHistStepData(self, histStep):

newHistStep = False
isSearchedHistStep = False
for line in hist.readlines():
for line in hist:
if not line.strip() and isSearchedHistStep:
break
elif not line.strip():
Expand Down
2 changes: 1 addition & 1 deletion lib/init/grass.py
Original file line number Diff line number Diff line change
Expand Up @@ -1990,7 +1990,7 @@ def print_params(params):
date_str = "#define GRASS_HEADERS_DATE "
gdate = gpath("include", "grass", "version.h")
with open(gdate) as filegdate:
for line in filegdate.readlines():
for line in filegdate:
if line.startswith(date_str):
sys.stdout.write(
"{}\n".format(
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ ignore = [
"FURB101", # read-whole-file
"FURB103", # write-whole-file.
"FURB118", # reimplemented-operator
"FURB129", # readlines-in-for
"FURB131", # delete-full-slice
"FURB140", # reimplemented-starmap
"FURB142", # for-loop-set-mutations
Expand Down
3 changes: 1 addition & 2 deletions python/grass/grassdb/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ def _read_from_plain_text(history_path):
history_path, encoding="utf-8", mode="r", errors="replace"
) as file_history:
content_list = [
{"command": line.strip(), "command_info": None}
for line in file_history.readlines()
{"command": line.strip(), "command_info": None} for line in file_history
]
except OSError as e:
raise OSError(
Expand Down
2 changes: 1 addition & 1 deletion python/grass/pygrass/raster/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def read_rules(self, filename, sep=":"):
"""
self.reset()
with open(filename, "r") as f:
for row in f.readlines():
for row in f:
cat = row.strip().split(sep)
if len(cat) == 2:
label, min_cat = cat
Expand Down
2 changes: 1 addition & 1 deletion python/grass/script/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ def region_env(region3d=False, flags=None, env=None, **kwargs):
)
with open(windfile, "r") as fd:
grass_region = ""
for line in fd.readlines():
for line in fd:
key, value = (x.strip() for x in line.split(":", 1))
if kwargs and key not in {"proj", "zone"}:
continue
Expand Down
2 changes: 1 addition & 1 deletion python/grass/script/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def db_select(sql=None, filename=None, table=None, env=None, **args):
fatal(_("Fetching data failed"))

ofile = open(fname)
result = [tuple(x.rstrip(os.linesep).split(args["sep"])) for x in ofile.readlines()]
result = [tuple(x.rstrip(os.linesep).split(args["sep"])) for x in ofile]
ofile.close()
try_remove(fname)

Expand Down
2 changes: 1 addition & 1 deletion scripts/d.frame/d.frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def read_monitor_file(monitor, ftype="env"):
fatal(_("Unable to get monitor info. %s"), e)

lines = []
for line in fd.readlines():
for line in fd:
lines.append(line)

fd.close()
Expand Down
2 changes: 1 addition & 1 deletion scripts/g.extension/g.extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,7 @@ def install_extension_std_platforms(name, source, url, branch):
if filename == "Makefile":
# get the module name: PGM = <module name>
with open(os.path.join(r, "Makefile")) as fp:
for line in fp.readlines():
for line in fp:
if re.match(r"PGM.*.=|PGM=", line):
try:
modulename = line.split("=")[1].strip()
Expand Down
2 changes: 1 addition & 1 deletion scripts/i.spectral/i.spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def draw_linegraph(what):
)
)
with open(gcore.parse_command("d.mon", flags="g", quiet=True)["env"]) as f:
for line in f.readlines():
for line in f:
if "GRASS_RENDER_FILE=" in line:
gcore.info(
_(
Expand Down
2 changes: 1 addition & 1 deletion scripts/r.pack/r.pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def main():
vrt = os.path.join(map_file["file"], "vrt")
if os.path.exists(vrt):
with open(vrt, "r") as f:
for r in f.readlines():
for r in f:
map, mapset = r.split("@")
map_basedir = os.path.sep.join(
os.path.normpath(
Expand Down
Loading