Skip to content

Commit

Permalink
style: Manual fixes for for-loop-writes (FURB122): Use of f.write i…
Browse files Browse the repository at this point in the history
…n a for loop
  • Loading branch information
echoix committed Jan 25, 2025
1 parent bd8d98c commit 6b79df9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
7 changes: 3 additions & 4 deletions lib/gis/testsuite/test_gis_lib_getl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ def read_lines_and_assert(self, get_line_function, newline):
"""Write and read lines and then assert they are as expected"""
lines = ["Line 1", "Line 2", "Line 3"]
with open(self.file_path, mode="w", newline=newline) as stream:
for line in lines:
# Python text newline here.
# The specific newline is added by the stream.
stream.write(f"{line}\n")
# Python text newline here.
# The specific newline is added by the stream.
stream.writelines(f"{line}\n" for line in lines)

file_ptr = self.libc.fopen(str(self.file_path).encode("utf-8"), b"r")
if not file_ptr:
Expand Down
15 changes: 6 additions & 9 deletions python/grass/gunittest/testsuite/test_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,14 @@ class TestMd5Sums(TestCase):
@classmethod
def setUpClass(cls):
with open(cls.correct_file_name_platform_nl, "w") as f:
for line in CORRECT_LINES:
# \n should be converted to platform newline
f.write(line + "\n")
# \n should be converted to platform newline
f.writelines(line + "\n" for line in CORRECT_LINES)
with open(cls.correct_file_name_unix_nl, "w") as f:
for line in CORRECT_LINES:
# binary mode will write pure \n
f.write(line + "\n")
# binary mode will write pure \n
f.writelines(line + "\n" for line in CORRECT_LINES)
with open(cls.wrong_file_name, "w") as f:
for line in INCORRECT_LINES:
# \n should be converted to platform newline
f.write(line + "\n")
# \n should be converted to platform newline
f.writelines(line + "\n" for line in INCORRECT_LINES)

@classmethod
def tearDownClass(cls):
Expand Down

0 comments on commit 6b79df9

Please sign in to comment.