Skip to content

Conversation

makslevental
Copy link
Contributor

@makslevental makslevental commented Oct 7, 2025

We're shadowing the Python builtin function globals in ir.py and therefore anywhere someone does from mlir.ir import *. So hide it.

@makslevental makslevental marked this pull request as ready for review October 7, 2025 18:28
@makslevental makslevental requested a review from jpienaar October 7, 2025 18:29
@llvmbot llvmbot added mlir:python MLIR Python bindings mlir labels Oct 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 7, 2025

@llvm/pr-subscribers-mlir

Author: Maksim Levental (makslevental)

Changes

We're shadowing the Python builtin function globals in ir.py and therefore anywhere someone does from mlir.ir import *. So hide it.


Full diff: https://github.com/llvm/llvm-project/pull/162339.diff

1 Files Affected:

  • (modified) mlir/python/mlir/ir.py (+7-7)
diff --git a/mlir/python/mlir/ir.py b/mlir/python/mlir/ir.py
index 7ddc70a35af96..11477d061e897 100644
--- a/mlir/python/mlir/ir.py
+++ b/mlir/python/mlir/ir.py
@@ -12,7 +12,7 @@
 from ._mlir_libs._mlir import (
     register_type_caster,
     register_value_caster,
-    globals,
+    globals as _globals,
 )
 from ._mlir_libs import (
     get_dialect_registry,
@@ -32,17 +32,17 @@ def loc_tracebacks(*, max_depth: int | None = None) -> Iterable[None]:
       max_depth: Maximum number of frames to include in the location.
         If None, the default limit is used.
     """
-    old_enabled = globals.loc_tracebacks_enabled()
-    old_limit = globals.loc_tracebacks_frame_limit()
+    old_enabled = _globals.loc_tracebacks_enabled()
+    old_limit = _globals.loc_tracebacks_frame_limit()
     try:
-        globals.set_loc_tracebacks_frame_limit(max_depth)
+        _globals.set_loc_tracebacks_frame_limit(max_depth)
         if not old_enabled:
-            globals.set_loc_tracebacks_enabled(True)
+            _globals.set_loc_tracebacks_enabled(True)
             yield
     finally:
         if not old_enabled:
-            globals.set_loc_tracebacks_enabled(False)
-        globals.set_loc_tracebacks_frame_limit(old_limit)
+            _globals.set_loc_tracebacks_enabled(False)
+        _globals.set_loc_tracebacks_frame_limit(old_limit)
 
 
 # Convenience decorator for registering user-friendly Attribute builders.

@makslevental makslevental merged commit aed73d2 into main Oct 7, 2025
14 checks passed
@makslevental makslevental deleted the users/makslevental/hide-globals branch October 7, 2025 19:23
Copy link
Member

@jpienaar jpienaar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:python MLIR Python bindings mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants