This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-tirx.git
The following commit(s) were added to refs/heads/main by this push:
new 8d5a72066 [FIX] Preserve loop enum formatting on Python 3.10 (#139)
8d5a72066 is described below
commit 8d5a72066f670eaa2283ceadc9a1dae98347f01f
Author: Tianqi Chen <[email protected]>
AuthorDate: Sat Oct 31 10:49:39 2026 -0400
[FIX] Preserve loop enum formatting on Python 3.10 (#139)
Construct `ForKind` directly when formatting reflected loop kinds,
preserving unknown values as integers. This keeps enum names available
on Python 3.10 and 3.11, where raw-value enum containment raises
`TypeError`.
---
python/tvm_tirx/ir/format_tree.py | 7 +++++--
tests/python/ir/test_ir_format_tree.py | 5 +++++
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/python/tvm_tirx/ir/format_tree.py
b/python/tvm_tirx/ir/format_tree.py
index d1230e1e9..3555e4243 100644
--- a/python/tvm_tirx/ir/format_tree.py
+++ b/python/tvm_tirx/ir/format_tree.py
@@ -213,8 +213,11 @@ class _TreeFormatter:
and role != "ignore"
else None
)
- if isinstance(value, For) and field.name == "kind" and child
in ForKind:
- child = ForKind(child) # Stored as an int; show the enum
name.
+ if isinstance(value, For) and field.name == "kind":
+ try:
+ child = ForKind(child) # Stored as an int; show the
enum name.
+ except ValueError:
+ pass # Keep unknown enum values as integers.
entries.append((field.name, child, role, action))
return name, "object", entries
return type(value).__name__, "opaque", []
diff --git a/tests/python/ir/test_ir_format_tree.py
b/tests/python/ir/test_ir_format_tree.py
index 49516082e..67345ae72 100644
--- a/tests/python/ir/test_ir_format_tree.py
+++ b/tests/python/ir/test_ir_format_tree.py
@@ -244,6 +244,11 @@ def test_native_loop_defaults_and_structural_comparison():
)
[email protected]("kind", [-1, 4])
+def test_unknown_loop_kind_remains_an_integer(kind):
+ assert f"kind={kind}" in ir.format_tree(make_loop(kind=kind))
+
+
@py_class("testing.tree.DefaultVar")
class TreeDefaultVar(tvm_ffi.Object):
value: Any = ir.Var("default", "int32")