Repository navigation
[BugFix][TVMScript] Fix invalid f-string format spec causing TypeError on Python 3.14 - #19362
Merged
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).
tlopex
approved these changes
Apr 6, 2026
tlopex
left a comment
Member
There was a problem hiding this comment.
LGTM! Thank you for the contribution! @soowonj
Aharrypotter
pushed a commit
to Aharrypotter/tvm
that referenced
this pull request
Apr 10, 2026
…r on Python 3.14 (apache#19362) ## Problem On Python 3.14, any use of TVMScript raises a `TypeError` before the module body is even parsed: ``` TypeError: unsupported format string passed to type.__format__ ``` The traceback points to `python/tvm/script/parser/core/diagnostics.py:120`: ```python raise TypeError(f"Source for {obj:!r} not found") ``` ## Root Cause `{obj:!r}` is an invalid f-string expression. The `:` introduces a `format_spec`, so `!r` is passed to `type.__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](https://peps.python.org/pep-0701/) 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 ```diff - raise TypeError(f"Source for {obj:!r} not found") + raise TypeError(f"Source for {obj!r} not found") ``` One character change. Valid across all Python versions >= 3.6. ## Testing Verified on Python 3.14.2 (darwin/arm64): - TVMScript `ir_module` + `prim_func` parses and compiles correctly after the fix - Full TVMScript test suite: **628 passed, 1 xfailed** (the 1 failure in `test_tvmscript_roundtrip.py::test_roundtrip[relax_symbolic_size_var]` is pre-existing and unrelated to this change)
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)