Repository navigation
fix: preserve inline comments on skipped docstrings - #412
Draft
Dodothereal wants to merge 1 commit into
Draft
Dodothereal wants to merge 1 commit into
Dodothereal wants to merge 1 commit 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 excluded by --range or --docstring-length can still crash when an inline comment follows it. For example,
"""doc.""" # noqa: D400with --range 20 30 raisesValueError: start (1,12) precedes previous end (2,0).The unformatted-docstring path was inserting a synthetic newline before the existing comment. Pass the following token into that path and leave the comment and its newline in their original order.
This adds 364 regression parameter combinations covering range and length exclusions, --black, LF/CRLF, EOF with or without a final newline, several docstring contexts, unchanged content, idempotence, and continued formatting of another selected docstring. The existing helper test is updated for the new argument.
Validation history:
e52e172210ed0d2da1e5ed2a0bf2c3718ab3c72e. 364 new regression cases and 180 existing test cases passed in a module-level harness, plus 2,914 additional independent regression permutations.uv, dedicated venv, editable installdocformatter==1.7.8verified fromsrc/docformatter/__init__.py,VIRTUAL_ENVset for CLI entry point tests):e52e172210ed0d2da1e5ed2a0bf2c3718ab3c72e):tests/formatter/test_skipped_docstring_comments.py: 364 passed, 0 failed (0.23s).test_docformatter.py,test_configuration_functions.pyvia legitimate entry point): 95 passed, 0 failed (1.13s).2a6f2742fee1fa14dc38587b1d34cd81519fb2d4):tests/formatter/test_skipped_docstring_comments.py: 284 failed, 80 passed (failing withValueError: start precedes previous endwhen an inline comment follows a skipped docstring; note that 80 cases pass on baseline where comments/tokens did not trigger the collision).py310,py311,py313,py314,pypy3) and pre-commit hooks were not run in this local follow-up validation. GitHub Actions test matrix (6 test jobs across supported versions + lint) is all-green on this commit.AI Assistance Disclosure:
Related to #346, but this addresses the skipped-docstring path rather than the already-fixed formatted-docstring case.