From 729b76f454cb947a4ce88760597153be19fc35ff Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 12 Aug 2025 10:21:38 +1000 Subject: [PATCH] Cleanup: use str.format to format strings in Python Also replace redundant `{!s}` with `{:s}`. --- doc/blender_file_format/BlendFileDnaExporter_25.py | 2 +- intern/cycles/blender/addon/osl.py | 2 +- scripts/addons_core/bl_pkg/cli/blender_ext.py | 2 +- scripts/modules/_blendfile_header.py | 10 +++++----- scripts/startup/bl_ui/space_graph.py | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/blender_file_format/BlendFileDnaExporter_25.py b/doc/blender_file_format/BlendFileDnaExporter_25.py index d508091162b..daf52e85ec7 100755 --- a/doc/blender_file_format/BlendFileDnaExporter_25.py +++ b/doc/blender_file_format/BlendFileDnaExporter_25.py @@ -435,7 +435,7 @@ def main(): os.remove(Path_Blend) # export dna to xhtml - log.info("6: export sdna to xhtml file: %r" % Path_HTML) + log.info("6: export sdna to xhtml file: {!r}".format(Path_HTML)) handleHTML = open(Path_HTML, "w") catalog.WriteToHTML(handleHTML) handleHTML.close() diff --git a/intern/cycles/blender/addon/osl.py b/intern/cycles/blender/addon/osl.py index bcc22cc5460..3a9e605a488 100644 --- a/intern/cycles/blender/addon/osl.py +++ b/intern/cycles/blender/addon/osl.py @@ -232,7 +232,7 @@ def update_internal_script(report, script): import traceback traceback.print_exc() - report({'ERROR'}, "Cannot read OSO bytecode to store in node at %r" % oso_path) + report({'ERROR'}, "Cannot read OSO bytecode to store in node at {!r}".format(oso_path)) ok = False return ok, oso_path, bytecode, bytecode_hash diff --git a/scripts/addons_core/bl_pkg/cli/blender_ext.py b/scripts/addons_core/bl_pkg/cli/blender_ext.py index 9eed290743f..43e35886629 100755 --- a/scripts/addons_core/bl_pkg/cli/blender_ext.py +++ b/scripts/addons_core/bl_pkg/cli/blender_ext.py @@ -1382,7 +1382,7 @@ def url_retrieve_to_data_iter( if size >= 0 and read < size: raise ContentTooShortError( - "retrieval incomplete: got only %i out of %i bytes" % (read, size), + "retrieval incomplete: got only {:d} out of {:d} bytes".format(read, size), response_headers, ) diff --git a/scripts/modules/_blendfile_header.py b/scripts/modules/_blendfile_header.py index 4c1e8d72331..7a2767e69c5 100644 --- a/scripts/modules/_blendfile_header.py +++ b/scripts/modules/_blendfile_header.py @@ -87,7 +87,7 @@ class BlendFileHeader: bytes_0_6 = file.read(7) if bytes_0_6 != b'BLENDER': - raise BlendHeaderError("invalid first bytes %r" % bytes_0_6) + raise BlendHeaderError("invalid first bytes {!r}".format(bytes_0_6)) self.magic = bytes_0_6 byte_7 = file.read(1) @@ -99,21 +99,21 @@ class BlendFileHeader: elif byte_7 == b'-': self.pointer_size = 8 else: - raise BlendHeaderError("invalid pointer size %r" % byte_7) + raise BlendHeaderError("invalid pointer size {!r}".format(byte_7)) byte_8 = file.read(1) if byte_8 == b'v': self.is_little_endian = True elif byte_8 == b'V': self.is_little_endian = False else: - raise BlendHeaderError("invalid endian indicator %r" % byte_8) + raise BlendHeaderError("invalid endian indicator {!r}".format(byte_8)) bytes_9_11 = file.read(3) self.version = int(bytes_9_11) else: byte_8 = file.read(1) header_size = int(byte_7 + byte_8) if header_size != 17: - raise BlendHeaderError("unknown file header size %d" % header_size) + raise BlendHeaderError("unknown file header size {:d}".format(header_size)) byte_9 = file.read(1) if byte_9 != b'-': raise BlendHeaderError("invalid file header") @@ -121,7 +121,7 @@ class BlendFileHeader: byte_10_11 = file.read(2) self.file_format_version = int(byte_10_11) if self.file_format_version != 1: - raise BlendHeaderError("unsupported file format version %r" % self.file_format_version) + raise BlendHeaderError("unsupported file format version {:d}".format(self.file_format_version)) byte_12 = file.read(1) if byte_12 != b'v': raise BlendHeaderError("invalid file header") diff --git a/scripts/startup/bl_ui/space_graph.py b/scripts/startup/bl_ui/space_graph.py index 89a91c9f1e3..c0d05577e2c 100644 --- a/scripts/startup/bl_ui/space_graph.py +++ b/scripts/startup/bl_ui/space_graph.py @@ -28,15 +28,15 @@ def drivers_editor_footer(layout, context): return layout.separator_spacer() - layout.label(text="Driver: {!s} ({!s})".format(act_fcurve.id_data.name, act_fcurve.data_path)) + layout.label(text="Driver: {:s} ({:s})".format(act_fcurve.id_data.name, act_fcurve.data_path)) if act_driver.variables: layout.separator(type='LINE') - layout.label(text="Variables: %i" % len(act_driver.variables)) + layout.label(text="Variables: {:d}".format(len(act_driver.variables))) if act_driver.type == 'SCRIPTED' and act_driver.expression: layout.separator(type='LINE') - layout.label(text="Expression: %s" % act_driver.expression) + layout.label(text="Expression: {:s}".format(act_driver.expression)) class GRAPH_HT_header(Header):