Don't drop comments inside __all__, and only read markers from comments - #63
Merged
Merged
Conversation
- Rewriting a multi-line __all__ rebuilt the literal and deleted comments inside it. Such an __all__ is now reported but not rewritten. - The message for an __all__ that can't be rewritten said it was built from several statements, also when it was a non-literal like ["A"] + ["B"]; it now names all the reasons. - `# unexport: not-public` / `public` were matched against whole physical lines, so the text inside a string literal marked the name. Only comment tokens count now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019P9bvuGwAyVCNUdsAYPB1V
hakancelikdev
merged commit Sep 25, 2026
6a45e12
into
claude/issuelari-gorme-fpbbfd
26 checks passed
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.
From the core-dev review of the integration branch.
Problems
__all__were deleted on rewrite, because the literal is rebuilt from scratch. This also happens onmain.__all__unchanged, the message always said it "is built from several statements". That was wrong for a single["A"] + ["B"].# unexport: not-public/publicwere matched against the whole physical line, soX = "# unexport: not-public"markedX. This also happens onmain.Fix
refactor._has_commentstokenizes the source and returns the source unchanged when a comment lies inside the literal's span. It converts the AST's UTF-8 byte column to a character column for the closing line. A comment after the literal (__all__ = [...] # public API) is still kept by the normal rewrite.set_extra_attronly looks atCOMMENTtokens.Tests
test_refactorcases: comments inside the literal leave it untouched, and a trailing comment survives a rewrite.test_marker_inside_a_string_is_not_a_comment.🤖 Generated with Claude Code
https://claude.ai/code/session_019P9bvuGwAyVCNUdsAYPB1V
Generated by Claude Code