Repository navigation
fix: leave docstrings with a backslash line continuation alone - #416
Open
Kernel-Hunter wants to merge 2 commits into
Open
Kernel-Hunter wants to merge 2 commits into
Kernel-Hunter wants to merge 2 commits into
Conversation
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.
A docstring that starts with a backslash line continuation gets a literal backslash in its text after formatting. This module docstring comes from CPython's
socket.py:docformatterturns it intoThe backslash used to join the lines. Now
\is an invalid escape that keeps the backslash, so__doc__starts with\ This moduleand Python warns about the escape sequence. The same happens for a continuation in the middle of a description (goes on \followed byand continuesbecomesgoes on \ and continues), and for raw docstrings._do_format_docstringnow returns the docstring unchanged when any line of it ends in an odd number of backslashes, which is a continuation. Docstrings with an even run, a literal backslash, are still formatted. I found it by runningdocformatterover the 150 top-level stdlib modules and comparing each docstring's text before and after.tests/formatter/test_docstring_line_continuation.pycovers a leading continuation, a method docstring, a continuation inside the description and a raw docstring. All four fail on master. The rest oftests/formatterandtests/test_string_functions.pypass; the end-to-end tests that error in my checkout (29, a missingVIRTUAL_ENVvariable in my shell) error the same way on master.