Fix docstring indentation with leading tabs#5148
Merged
Merged
Conversation
Collaborator
|
Thanks! |
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.
Description
Closes #3667.
Black expands leading tabs in multiline docstrings before it computes the docstring indentation to strip. That expansion used Python's default 8-column tab stops, while Black normalizes surrounding code indentation to 4 spaces. As a result, nested tabs inside indented docstrings were doubled in the formatted output.
This changes the docstring-only leading-tab expansion to use 4-space columns, updates the existing tabbed docstring fixture, and adds a focused regression case from the issue shape.
Checklist - did you ...
--previewstyle, following the stability policy?CHANGES.mdif necessary?Tests
.venv/bin/python -m pytest tests/test_format.py -k 'docstring or multiline_strings or string_prefixes' -q.venv/bin/python -m pytest tests/test_black.py -k 'docstring or lines_with_leading_tabs_expanded' -q.venv/bin/python -m pytest tests --run-optional no_jupyter -n auto -q -k 'not expression_diff_with_color and not piping_diff_with_color'env -u NO_COLOR TERM=xterm-256color .venv/bin/python -m pytest tests/test_black.py -k 'expression_diff_with_color or piping_diff_with_color' -q.venv/bin/python -m black --check --verbose src/black/strings.py tests/test_black.pySKIP=prettier PRE_COMMIT_HOME="$PWD/.pre-commit-cache" PIP_CACHE_DIR="$PWD/.pip-cache" .venv/bin/pre-commit run --files CHANGES.md src/black/strings.py tests/test_black.py tests/data/cases/docstring.py tests/data/cases/docstring_tabs.pyThe prettier hook was skipped locally because nodeenv failed SSL certificate verification while downloading Node; the other pre-commit hooks passed.