From 2b186fceb8b3da3104e1ad7635b522aca481663f Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 24 Jan 2026 23:02:39 +0200 Subject: [PATCH] Use __spec__.parent instead of calculating each time --- src/PIL/Image.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 743632e1f..3e37754e1 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -416,7 +416,7 @@ def _import_plugin_for_extension(ext: str | bytes) -> bool: try: logger.debug("Importing %s", plugin) - __import__(f"PIL.{plugin}", globals(), locals(), []) + __import__(f"{__spec__.parent}.{plugin}", globals(), locals(), []) return True except ImportError as e: logger.debug("Image: failed to import %s: %s", plugin, e) @@ -481,11 +481,10 @@ def init() -> bool: if _initialized >= 2: return False - parent_name = __name__.rpartition(".")[0] for plugin in _plugins: try: logger.debug("Importing %s", plugin) - __import__(f"{parent_name}.{plugin}", globals(), locals(), []) + __import__(f"{__spec__.parent}.{plugin}", globals(), locals(), []) except ImportError as e: logger.debug("Image: failed to import %s: %s", plugin, e)