[Mlir-commits] [mlir] [mlir:python] Fail immediately if importing an initializer module raises (PR #74595)

Peter Hawkins llvmlistbot at llvm.org
Wed Dec 6 06:20:58 PST 2023


https://github.com/hawkinsp created https://github.com/llvm/llvm-project/pull/74595

ImportError.

If ImportError is raised, _site_initialize will fail because 'm' will be an unbound local. Just return False in this case and fail fast.

@stellaraccident @makslevental 

>From c2645d7eee8333b0aeb8abd787398a79efaaa90c Mon Sep 17 00:00:00 2001
From: Peter Hawkins <phawkins at google.com>
Date: Wed, 6 Dec 2023 14:17:51 +0000
Subject: [PATCH] [mlir:python] Fail immediately if importing an initializer
 module raises ImportError.

If ImportError is raised, _site_initialize will fail because 'm' will
be an unbound local. Just return False in this case and fail fast.
---
 mlir/python/mlir/_mlir_libs/__init__.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mlir/python/mlir/_mlir_libs/__init__.py b/mlir/python/mlir/_mlir_libs/__init__.py
index 32f46d24cc739..98dbbc6adf9ce 100644
--- a/mlir/python/mlir/_mlir_libs/__init__.py
+++ b/mlir/python/mlir/_mlir_libs/__init__.py
@@ -94,6 +94,7 @@ def process_initializer_module(module_name):
                 "encountered otherwise and the MLIR Python API may not function."
             )
             logger.warning(message, exc_info=True)
+            return False
 
         logger.debug("Initializing MLIR with module: %s", module_name)
         if hasattr(m, "register_dialects"):



More information about the Mlir-commits mailing list