Repository navigation
Fix long string return annotations when parameters split - #5404
Closed
fire-mirror wants to merge 4 commits into
Closed
fire-mirror wants to merge 4 commits into
fire-mirror wants to merge 4 commits into
Conversation
4 tasks done
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.
Closes #3926.
Problem
With unstable string processing enabled, a long string return annotation is initially
wrapped in optional parentheses so
StringSplittercan split it. When the function'sparameters also require a left-hand split, the optional parentheses are removed before
the return annotation reaches
StringSplitter. The annotation is then left on anoverlong line.
Changes
list is split, allowing the existing string-processing pipeline to split the
annotation.
StringSplitter's breakpoint rules so literals without a legal split remainunchanged.
of sending them through the string-splitting path.
pair remains visible to subsequent transformers.
StringSplittercannot splitthem, with regression coverage for that boundary.
The change is limited to the unstable string-processing path and retains the existing
public API.
Validation
tests/test_format.py: 236 passedtests/test_trans.py: 1 passedpreview_return_annotation_brackets_stringfixture: 1 passedpre-commit run --files src/black/linegen.py src/black/trans.py tests/data/cases/preview_return_annotation_brackets_string.py CHANGES.md: all hooks passedthe annotation and is stable on a second formatting pass.
# noqa, and# type: ignorereturn annotations.Checklist
--unstable/preview style policy.CHANGES.mdentry.