Cleanup: minor change to string formatting & __file__

Use __repr__ for formatting file instead of __str__ because non-standard
characters will be escaped and the string will be properly quoted.

Also, a modules __file__ is not *guaranteed* to be a string
(although it almost always is), nevertheless, __repr__ generally
results more more humanly readable results.

Note that __repr__ was already used to format __file__ in most places.
This commit is contained in:
Campbell Barton
2024-04-27 11:44:27 +10:00
parent 8250b202e8
commit dd864603f1
2 changed files with 8 additions and 3 deletions

View File

@@ -235,7 +235,7 @@ def load_scripts(*, reload_scripts=False, refresh_scripts=False, extensions=True
import traceback
traceback.print_exc()
else:
print("\nWarning! '%s' has no register function, "
print("\nWarning! %r has no register function, "
"this is now a requirement for registerable scripts" %
mod.__file__)

View File

@@ -223,7 +223,12 @@ def write_sysinfo(filepath):
if addon_mod is None:
output.write("%s (MISSING)\n" % (addon))
else:
output.write("%s (version: %s, path: %s)\n" %
(addon, addon_mod.bl_info.get('version', "UNKNOWN"), addon_mod.__file__))
output.write(
"%s (version: %s, path: %r)\n" % (
addon,
addon_mod.bl_info.get("version", "UNKNOWN"),
addon_mod.__file__,
)
)
except BaseException as ex:
output.write("ERROR: %s\n" % ex)