Fix string_processing error with unassigned long string literal with trailing comma
#4929
+59
−1
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.
Description
This PR fixes issue #4912 where
string_processingwould crash with anINTERNAL ERRORwhen processing an unassigned long string literal with a trailing comma (creating a
one-item tuple).
The Problem: When a line contains only a long string literal followed by a trailing
comma (making it a one-item tuple) and is not inside brackets,
StringSplitterwouldsplit the string into multiple implicitly concatenated strings. This created multiple
expressions where only the last has the comma, breaking AST equivalence:
The Fix:
StringSplitter.do_splitter_match()now detects theSTRING + COMMApattern (bareone-item tuple not inside brackets) and returns an error, deferring to
StringParenWrapperStringParenWrapper._trailing_comma_tuple_match()is a new method that matches thisspecific pattern
semantics:
Checklist - did you ...
Implement any code style changes under the
--previewstyle, following thestability policy? > Yes,
string_processingis an unstable feature enabled via--preview --enable-unstable-feature=string_processingAdd an entry in
CHANGES.mdif necessary? > Added under "Preview style" in theUnreleased section
Add / update tests if necessary? > Added test case in
tests/data/cases/preview_long_strings.pyAdd new / update outdated documentation? > No documentation changes needed - this
is a bugfix for existing functionality
Fixes #4912
closes #4917