Fix implicit concatenation of t-string literals with str or bytes - #11635
Fix implicit concatenation of t-string literals with str or bytes#11635Henry Su (hsusul) wants to merge 1 commit into
Conversation
PEP 750 and CPython 3.14 reject mixing t-string literals with string or bytes literals. Report that mix instead of inferring Template.
|
🔒 Automated review in progress — Rich Chiodo (@rchiodo) is auto-reviewing this PR. |
| t5 = "" t"x" | ||
|
|
||
| # This should generate an error. | ||
| t6 = t"x" "y" |
There was a problem hiding this comment.
Warning · Non-blocking recommendation
The tests only contribute to an aggregate diagnostic count and do not verify the new Unknown recovery type. Add reveal_type coverage for at least one mixed expression so a regression to Template inference cannot pass.
[verified]
|
Non-blocking follow-up: mirror this validation in Pylance's |
Rich Chiodo (rchiodo)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
| configOptions.defaultPythonVersion = pythonVersion3_14; | ||
| const analysisResults1 = TestUtils.typeAnalyzeSampleFiles(['tstring2.py'], configOptions); | ||
| TestUtils.validateResults(analysisResults1, 1); | ||
| TestUtils.validateResults(analysisResults1, 6); |
There was a problem hiding this comment.
Warning · Non-blocking recommendation
The aggregate count does not verify that mixed literals receive the new diagnostic and are typed as Unknown; another diagnostic could preserve the count while this behavior regresses. Add reveal_type(..., expected_text="Unknown") coverage for a representative invalid form and a diagnostic-specific assertion if supported by the harness.
Rich Chiodo (rchiodo)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
Heejae Chang (heejaechang)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
Summary
str,bytes, or f-string literal (SyntaxError: cannot mix t-string literals with string or bytes literals).t"x" "y"and"" t"x", and inferredTemplate. Adjacent t-string literals (t"a" t"b") remain valid.Unknown.Reproduction (Python 3.14)
CPython:
Root cause
getTypeOfStringListtreated any string list containing a t-string asTemplate, including mixed implicit concatenations. That matched an earlier draft of PEP 750; the final spec and CPython 3.14 disallowTemplate/str(andTemplate/bytes) implicit concatenation.Test plan
tstring2.py: valid t-string implicit concat; mix withstr, f-string, andbytes; explicitTemplate + TemplatevsTemplate + strnpx jest typeEvaluator4.test.ts -t TString --forceExit(pass)npx jest typeEvaluator4.test.ts --forceExit(155 passed)npx jest localizer.test.ts --forceExit(pass)npx jest typeEvaluator8.test.ts -t Strings2 --forceExitfrompackages/pyright-internal(pass)ESLINT_USE_FLAT_CONFIG=false npx eslinton changed TS files (pass)npx prettier -con changed TS/JSON files (pass)npx lerna exec --stream --no-bail --ignore=pyright -- "tsc --noEmit"(pass)git diff --check(pass)Full
packages/pyright-internalnpm testwas not run (includes webpack test server + entire Jest suite). Analyzer coverage for this change is the TString / string-concatenation sample tests.