Align t-string/bytes mix error with CPython 3.14 - #27766
Merged
MichaReiser merged 2 commits intoAug 19, 2026
Merged
Conversation
Sacrimento
marked this pull request as ready for review
August 14, 2026 21:19
MichaReiser
reviewed
Aug 16, 2026
Sacrimento
force-pushed
the
align-tstrings-errors-w-CPython
branch
from
August 16, 2026 18:05
a789838 to
0fe5e30
Compare
Memory usage reportMemory usage unchanged ✅ |
|
MichaReiser
reviewed
Aug 17, 2026
|
Implicitly concatenating a t-string with a bytes literal (e.g. `t'a' b'b'`) reported the generic bytes-mixing error instead of the t-string-specific one, even though that message already existed for this case. CPython3.14's implementation reports the first incompatible pair of strings. However a t-string mismatch always takes precedence over a bytes mismatch within that pair. This change replaces the check with a pairwise scan over adjacent literals, matching CPython's diagnostics.
Sacrimento
force-pushed
the
align-tstrings-errors-w-CPython
branch
from
August 18, 2026 18:57
0fe5e30 to
460a72c
Compare
1 task
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.
Summary
Implicitly concatenating a t-string with a bytes literal (e.g.
t'a' b'b') reported the generic bytes-mixing error instead of the t-string specific one, even though that message already existed for this case. With CPython3.14 implementation, in a mismatched pair of adjacent literals containing a t-string, the t-string error is always reported over a bytes error, regardless of order. This does not apply for pairs not containing t-strings.This behavior can be observed with the following:
CPython 3.14
Ruff
This change replaces the check with a pairwise scan over adjacent literals, matching CPython's diagnostics.
Test Plan
These changes can be tested using the commands found above: both error messages should be equal.
I also added a unit test
inline_err::mixed_tstring_and_bytes_literals.pyto ensure ruff always prefers the t-string error as CPython 3.14 does.Lastly, I have this script (AI-provided) comparing Ruff's and CPython's outputs with all possible combinations of string, bytes, f-strings and t-strings:
cross-check.py