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 354c06926 [FIX] Accept generic function decorators on Python 3.13
(#110)
354c06926 is described below
commit 354c069262a0042786a67eece63f49962cfed9ba
Author: Tianqi Chen <[email protected]>
AuthorDate: Wed Oct 28 11:08:22 2026 -0400
[FIX] Accept generic function decorators on Python 3.13 (#110)
Recognize Python 3.13 generic function construction when validating
definition-site decorators. Skip the PUSH_NULL call opcode while
preserving the existing function-code and decorator-source checks.
---
python/tvm_tirx/script/parser/inspect_source.py | 1 +
tests/python/tirx/script/test_dynamic_shape.py | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/python/tvm_tirx/script/parser/inspect_source.py
b/python/tvm_tirx/script/parser/inspect_source.py
index 63be72f3f..83bc40848 100644
--- a/python/tvm_tirx/script/parser/inspect_source.py
+++ b/python/tvm_tirx/script/parser/inspect_source.py
@@ -296,6 +296,7 @@ def require_definition_site(
"CALL",
"CALL_FUNCTION",
"PRECALL",
+ "PUSH_NULL",
"CACHE",
"EXTENDED_ARG",
"SET_FUNCTION_ATTRIBUTE",
diff --git a/tests/python/tirx/script/test_dynamic_shape.py
b/tests/python/tirx/script/test_dynamic_shape.py
index c04bd9c7b..a1de09728 100644
--- a/tests/python/tirx/script/test_dynamic_shape.py
+++ b/tests/python/tirx/script/test_dynamic_shape.py
@@ -19,6 +19,7 @@
from __future__ import annotations
+import runpy
import sys
import pytest
@@ -124,6 +125,29 @@ def
test_tir_return_annotation_does_not_define_symbolic_var():
return A
[email protected](sys.version_info < (3, 12), reason="PEP 695 requires
Python 3.12")
[email protected]("type_param", ["n", "n: T.int32"])
+def test_generic_function_decorators(tmp_path, type_param):
+ source = f"""from __future__ import annotations
[email protected]
+def standalone[{type_param}](A: T.Tensor((n,), T.float32)):
+ T.evaluate(n)
+
[email protected]_module
+class Module:
+ @T.function
+ def member[{type_param}](A: T.Tensor((n,), T.float32)):
+ T.evaluate(n)
+"""
+ path = tmp_path / "generic_functions.py"
+ path.write_text(source)
+ namespace = runpy.run_path(str(path), init_globals={"T": T, "I": I})
+ for function in [namespace["standalone"], namespace["Module"]["member"]]:
+ n = function.params[0].ty.shape[0]
+ assert n.ty.dtype == "int32"
+ assert function.body[0].value.same_as(n)
+
+
@pytest.mark.skipif(sys.version_info < (3, 12), reason="PEP 695 requires
Python 3.12")
def test_type_vars_roundtrip():
M = T.dynamic("M")