diff --git a/cpp/build-support/asan_symbolize.py b/cpp/build-support/asan_symbolize.py index 8bab72b661e..5328904581c 100755 --- a/cpp/build-support/asan_symbolize.py +++ b/cpp/build-support/asan_symbolize.py @@ -171,7 +171,7 @@ def symbolize(self, addr, binary, offset): # foo(type1, type2) (in object.name) (filename.cc:80) match = re.match(r'^(.*) \(in (.*)\) \((.*:\d*)\)$', atos_line) if DEBUG: - print('atos_line: {0}'.format(atos_line)) + print(f'atos_line: {atos_line}') if match: function_name = match.group(1) function_name = re.sub(r'\(.*?\)', '', function_name) diff --git a/cpp/build-support/fuzzing/pack_corpus.py b/cpp/build-support/fuzzing/pack_corpus.py index 2064fed608d..07fc09f9026 100755 --- a/cpp/build-support/fuzzing/pack_corpus.py +++ b/cpp/build-support/fuzzing/pack_corpus.py @@ -31,13 +31,12 @@ def process_dir(corpus_dir, zip_output): for child in corpus_dir.iterdir(): if not child.is_file(): - raise IOError("Not a file: {0}".format(child)) + raise IOError(f"Not a file: {child}") with child.open('rb') as f: data = f.read() arcname = hashlib.sha1(data).hexdigest() if arcname in seen: - raise ValueError("Duplicate hash: {0} (in file {1})" - .format(arcname, child)) + raise ValueError(f"Duplicate hash: {arcname} (in file {child})") zip_output.writestr(str(arcname), data) seen.add(arcname) @@ -49,6 +48,6 @@ def main(corpus_dir, zip_output_name): if __name__ == "__main__": if len(sys.argv) != 3: - print("Usage: {0} ".format(sys.argv[0])) + print(f"Usage: {sys.argv[0]} ") sys.exit(1) main(sys.argv[1], sys.argv[2]) diff --git a/cpp/build-support/iwyu/iwyu_tool.py b/cpp/build-support/iwyu/iwyu_tool.py index 1429e0c0ee3..a0ee11a0296 100755 --- a/cpp/build-support/iwyu/iwyu_tool.py +++ b/cpp/build-support/iwyu/iwyu_tool.py @@ -204,7 +204,7 @@ def main(compilation_db_path, source_files, verbose, formatter, iwyu_args): if matches: entries.extend(matches) else: - print("{} not in compilation database".format(source)) + print(f"{source} not in compilation database") # TODO: As long as there is no complete compilation database available this check cannot be performed pass #print('WARNING: \'%s\' not found in compilation database.', source) diff --git a/cpp/build-support/lint_cpp_cli.py b/cpp/build-support/lint_cpp_cli.py index 47abd53fe92..59eff50541f 100755 --- a/cpp/build-support/lint_cpp_cli.py +++ b/cpp/build-support/lint_cpp_cli.py @@ -121,7 +121,7 @@ def lint_files(): if __name__ == '__main__': failures = list(lint_files()) for path, why, i, line in failures: - print('File {0} failed C++/CLI lint check: {1}\n' - 'Line {2}: {3}'.format(path, why, i + 1, line)) + print(f'File {path} failed C++/CLI lint check: {why}\n' + f'Line {i + 1}: {line}') if failures: exit(1) diff --git a/cpp/build-support/run_clang_format.py b/cpp/build-support/run_clang_format.py index 96487251d00..35b16f73ec0 100755 --- a/cpp/build-support/run_clang_format.py +++ b/cpp/build-support/run_clang_format.py @@ -38,8 +38,7 @@ def _check_one_file(filename, formatted): original.decode('utf8').splitlines(True), formatted.decode('utf8').splitlines(True), fromfile=filename, - tofile="{} (after clang format)".format( - filename))) + tofile=f"{filename} (after clang format)")) else: diff = None @@ -85,8 +84,7 @@ def _check_one_file(filename, formatted): if arguments.fix: if not arguments.quiet: - print("\n".join(map(lambda x: "Formatting {}".format(x), - formatted_filenames))) + print("\n".join(f"Formatting {x}" for x in formatted_filenames)) # Break clang-format invocations into chunks: each invocation formats # 16 files. Wait for all processes to complete @@ -122,9 +120,9 @@ def _check_one_file(filename, formatted): # check the output from each invocation of clang-format in parallel for filename, diff in pool.starmap(_check_one_file, checker_args): if not arguments.quiet: - print("Checking {}".format(filename)) + print(f"Checking {filename}") if diff: - print("{} had clang-format style issues".format(filename)) + print(f"{filename} had clang-format style issues") # Print out the diff to stderr error = True # pad with a newline diff --git a/cpp/build-support/run_cpplint.py b/cpp/build-support/run_cpplint.py index a81acf2eb2f..ab8bb0d3166 100755 --- a/cpp/build-support/run_cpplint.py +++ b/cpp/build-support/run_cpplint.py @@ -78,7 +78,7 @@ def _check_some_files(completed_processes, filenames): if arguments.quiet: cmd.append('--quiet') else: - print("\n".join(map(lambda x: "Linting {}".format(x), + print("\n".join(map(lambda x: f"Linting {x}", linted_filenames))) # lint files in chunks: each invocation of cpplint will process 16 files diff --git a/cpp/src/arrow/util/bpacking64_codegen.py b/cpp/src/arrow/util/bpacking64_codegen.py index f9b06b4d8fc..88dc93ca657 100644 --- a/cpp/src/arrow/util/bpacking64_codegen.py +++ b/cpp/src/arrow/util/bpacking64_codegen.py @@ -73,7 +73,7 @@ def howmanybytes(bit): print("inline const uint8_t* unpack0_64(const uint8_t* in, uint64_t* out) {") -print(" for(int k = 0; k < {0} ; k += 1) {{".format(howmany(0))) +print(f" for(int k = 0; k < {howmany(0)} ; k += 1) {{") print(" out[k] = 0;") print(" }") print(" return in;") @@ -81,47 +81,44 @@ def howmanybytes(bit): for bit in range(1, 65): print("") - print( - "inline const uint8_t* unpack{0}_64(const uint8_t* in, uint64_t* out) {{".format(bit)) + print(f"inline const uint8_t* unpack{bit}_64(const uint8_t* in, uint64_t* out) {{") if(bit < 64): - print(" const uint64_t mask = {0}ULL;".format((1 << bit)-1)) + print(f" const uint64_t mask = {((1 << bit)-1)}ULL;") maskstr = " & mask" if (bit == 64): maskstr = "" # no need for k in range(howmanywords(bit)-1): - print(" uint64_t w{0} = util::SafeLoadAs(in);".format(k)) - print(" w{0} = arrow::BitUtil::FromLittleEndian(w{0});".format(k)) - print(" in += 8;".format(k)) + print(f" uint64_t w{k} = util::SafeLoadAs(in);") + print(f" w{k} = arrow::BitUtil::FromLittleEndian(w{k});") + print(" in += 8;") k = howmanywords(bit) - 1 if (bit % 2 == 0): - print(" uint64_t w{0} = util::SafeLoadAs(in);".format(k)) - print(" w{0} = arrow::BitUtil::FromLittleEndian(w{0});".format(k)) - print(" in += 8;".format(k)) + print(f" uint64_t w{k} = util::SafeLoadAs(in);") + print(f" w{k} = arrow::BitUtil::FromLittleEndian(w{k});") + print(" in += 8;") else: - print(" uint64_t w{0} = util::SafeLoadAs(in);".format(k)) - print(" w{0} = arrow::BitUtil::FromLittleEndian(w{0});".format(k)) - print(" in += 4;".format(k)) + print(f" uint64_t w{k} = util::SafeLoadAs(in);") + print(f" w{k} = arrow::BitUtil::FromLittleEndian(w{k});") + print(" in += 4;") for j in range(howmany(bit)): firstword = j * bit // 64 secondword = (j * bit + bit - 1)//64 firstshift = (j*bit) % 64 - firstshiftstr = " >> {0}".format(firstshift) + firstshiftstr = f" >> {firstshift}" if(firstshift == 0): firstshiftstr = "" # no need if(firstword == secondword): if(firstshift + bit == 64): - print(" out[{0}] = w{1}{2};".format( - j, firstword, firstshiftstr, firstshift)) + print(f" out[{j}] = w{firstword}{firstshiftstr};") else: - print(" out[{0}] = (w{1}{2}){3};".format( - j, firstword, firstshiftstr, maskstr)) + print(f" out[{j}] = (w{firstword}{firstshiftstr}){maskstr};") else: secondshift = (64-firstshift) - print(" out[{0}] = ((w{1}{2}) | (w{3} << {4})){5};".format( - j, firstword, firstshiftstr, firstword+1, secondshift, maskstr)) + print(f" out[{j}] = ((w{firstword}{firstshiftstr}) | " + f"(w{firstword+1} << {secondshift})){maskstr};") print("") print(" return in;") print("}") diff --git a/cpp/src/gandiva/make_precompiled_bitcode.py b/cpp/src/gandiva/make_precompiled_bitcode.py index 97d96f8a878..48ed040f065 100644 --- a/cpp/src/gandiva/make_precompiled_bitcode.py +++ b/cpp/src/gandiva/make_precompiled_bitcode.py @@ -37,8 +37,8 @@ def apply_template(template, data): if __name__ == "__main__": if len(sys.argv) != 4: - raise ValueError("Usage: {0}