Skip to content

Don't drop comments inside __all__, and only read markers from comments - #63

Merged
hakancelikdev merged 1 commit into
claude/issuelari-gorme-fpbbfdfrom
fix/comments-in-all
Sep 25, 2026
Merged

hakancelikdev merged 1 commit into
claude/issuelari-gorme-fpbbfdfrom
fix/comments-in-all

Conversation

@hakancelikdev

Copy link
Copy Markdown
Owner

From the core-dev review of the integration branch.

Problems

  1. Comments inside a multi-line __all__ were deleted on rewrite, because the literal is rebuilt from scratch. This also happens on main.
    __all__ = [
        "A",  # the main entry point
        # "Old",
    ]
  2. Misleading message. When the refactor left __all__ unchanged, the message always said it "is built from several statements". That was wrong for a single ["A"] + ["B"].
  3. Markers inside strings counted. # unexport: not-public / public were matched against the whole physical line, so X = "# unexport: not-public" marked X. This also happens on main.

Fix

  • refactor._has_comments tokenizes 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.
  • The message now lists every reason: built from several statements, not a plain list/tuple/set, or has comments inside.
  • set_extra_attr only looks at COMMENT tokens.
  • A changelog entry is added.

Tests

  • Two new test_refactor cases: comments inside the literal leave it untouched, and a trailing comment survives a rewrite.
  • test_marker_inside_a_string_is_not_a_comment.
  • The first and third fail before this change.
  • 3.10 / 3.12 / 3.14, pre-commit, mypy and the self-check all pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_019P9bvuGwAyVCNUdsAYPB1V


Generated by Claude Code

- 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
hakancelikdev merged commit 6a45e12 into claude/issuelari-gorme-fpbbfd Sep 25, 2026
26 checks passed
@hakancelikdev
hakancelikdev deleted the fix/comments-in-all branch October 2, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants