Renamed variable for first part of splitext to root

This commit is contained in:
Andrew Murray 2024-08-31 19:43:35 +10:00
parent 95194a2050
commit e0a75b6d69

View File

@ -98,13 +98,13 @@ class ImageFont:
def _load_pilfont(self, filename: str) -> None: def _load_pilfont(self, filename: str) -> None:
with open(filename, "rb") as fp: with open(filename, "rb") as fp:
image: ImageFile.ImageFile | None = None image: ImageFile.ImageFile | None = None
filename_body = os.path.splitext(filename)[0] root = os.path.splitext(filename)[0]
for ext in (".png", ".gif", ".pbm"): for ext in (".png", ".gif", ".pbm"):
if image: if image:
image.close() image.close()
try: try:
fullname = filename_body + ext fullname = root + ext
image = Image.open(fullname) image = Image.open(fullname)
except Exception: except Exception:
pass pass
@ -115,8 +115,7 @@ class ImageFont:
if image: if image:
image.close() image.close()
pre = filename_body msg = f"cannot find glyph data file {root}.{{png|gif|pbm}}"
msg = f"cannot find glyph data file {pre}.{{png|gif|pbm}}"
raise OSError(msg) raise OSError(msg)
self.file = fullname self.file = fullname
@ -937,7 +936,7 @@ def load_path(filename: str | bytes) -> ImageFont:
pass pass
msg = f"cannot find font file '{filename}' in `sys.path`" msg = f"cannot find font file '{filename}' in `sys.path`"
if os.path.exists(filename): if os.path.exists(filename):
msg += f" did you mean `ImageFont.load({filename})` instead?" msg += f", did you mean `ImageFont.load({filename})` instead?"
raise OSError(msg) raise OSError(msg)