[BugFix][TVMScript] Fix invalid f-string format spec causing TypeError on Python 3.14#19362
Merged
tlopex merged 3 commits intoapache:mainfrom Apr 6, 2026
Merged
Conversation
…ect_getfile
Replace `{obj:!r}` with `{obj!r}` in diagnostics.py. The colon-prefixed
form was treated as a format_spec by the f-string parser, which is invalid.
Python 3.14 re-implemented f-string parsing (PEP 701) and now strictly
validates format specs, causing a TypeError at import time when using
TVMScript on Python 3.14.
The correct syntax for repr() conversion in f-strings is `{obj!r}` (no colon).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Python 3.14, any use of TVMScript raises a
TypeErrorbefore the module body is even parsed:The traceback points to
python/tvm/script/parser/core/diagnostics.py:120:Root Cause
{obj:!r}is an invalid f-string expression. The:introduces aformat_spec, so!ris passed totype.__format__as a format string — which it does not support.The intended syntax for a
repr()conversion is{obj!r}(no colon).Python 3.14 re-implemented f-string parsing under PEP 701 and now strictly validates format specs, surfacing this latent bug. Python 3.10–3.13 silently passed the invalid spec to
__format__and happened not to raise in most code paths, so the bug went unnoticed.Fix
One character change. Valid across all Python versions >= 3.6.
Testing
Verified on Python 3.14.2 (darwin/arm64):
ir_module+prim_funcparses and compiles correctly after the fixtest_tvmscript_roundtrip.py::test_roundtrip[relax_symbolic_size_var]is pre-existing and unrelated to this change)