fix: accept raw-string (r""") docstring openers in both parsers - #251
Merged
Conversation
Two independent PyAutoHands docstring parsers silently mis-handled an r"""
opener. Neither raised, and there are currently zero raw narrative docstrings
in any workspace, which is why this never fired.
add_notebook_quotes._narrative_docstring_ranges tested
lines[start].startswith('"""'). A raw block is a perfectly good column-0
ast.Expr(Constant(str)), so it reached that test and failed it — the block was
dropped as a cell boundary and the tutorial prose shipped as a Python CODE
cell containing a bare string literal.
env_config._DOCSTRING_DELIM_RE matched a bare delimiter only. An r""" opener
was walked past and the block's CLOSER matched as an opener instead, inverting
docstring parity for the rest of the file: an __Env__ section further down was
read as if it sat outside a docstring and read_env_declaration returned None,
silently losing the ENV: declaration and rerouting the script's smoke profile.
Both sites now accept an optional r/R prefix on either delimiter. The notebook
converter replaces the opener line outright when it emits the cell, so the
prefix never reaches the generated artefact and output is byte-identical.
Six regression tests, each verified to fail without the source change:
test_add_notebook_quotes
- raw block converts byte-identically to the same block unprefixed
- all six prefix/delimiter forms produce identical output
test_env_config
- the PARITY case: declaration survives an EARLIER raw docstring (this is
what a single-block test would miss)
- declaration inside the raw block itself
- all six prefix/delimiter forms parse
test_strip_env_declarations
- an __Env__ section in a raw block strips as a plain one does
Checked and confirmed unaffected: generate_markdown.script_title (its regex
finds the """ after the r) and navigator (reads already-converted output).
Verified the boundary set did not widen — column-0 raw single-quoted strings,
assigned literals, raw bytes literals and f-strings all remain non-boundaries.
Unblocks the 41-file workspace raw-stringing task (PyAutoMind
draft/maintenance/workspaces/latex_raw_string_docstrings.md).
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.
Closes #250.
Two independent PyAutoHands docstring parsers silently mis-handled an
r"""opener. Neither raised, and there are currently zero raw narrative docstrings in any workspace, which is why this never fired.This blocks the 41-file workspace raw-stringing task (PyAutoMind
draft/maintenance/workspaces/latex_raw_string_docstrings.md): those tutorial docstrings carry LaTeX and must be raw — unprefixed,\thetais aTABfollowed byheta— and raw is exactly what these two parsers rejected.The two defects
add_notebook_quotes._narrative_docstring_rangestestedlines[start].startswith('"""'). A raw block is a perfectly good column-0ast.Expr(Constant(str)), so it reached that test and failed it — the block was dropped as a cell boundary and the tutorial prose shipped as a Python code cell containing a bare string literal.env_config._DOCSTRING_DELIM_REmatched a bare delimiter only. Anr"""opener was walked past and the block's closer matched as an opener instead, inverting docstring parity for the rest of the file: an__Env__section further down was read as if it sat outside a docstring andread_env_declarationreturnedNone, silently losing theENV:declaration and rerouting the script's smoke profile. Sevenautolens_workspacescripts carry__Env__sections.Reproduced against
main@cdea28con a probe pair differing only by anr:_narrative_docstring_ranges[(6,10)]— raw block dropped[(0,2), (6,10)]read_env_declarationNone['jax']The change
Both sites accept an optional
r/Rprefix on either delimiter. The notebook converter replaces the opener line outright when it emits the cell, so the prefix never reaches the generated artefact and output is byte-identical — which is what makes the downstream task's diff-empty gate meaningful.Six regression tests, each verified to fail with the source change reverted:
test_add_notebook_quotes— raw block converts byte-identically to the same block unprefixed; all six prefix/delimiter forms produce identical output.test_env_config— the parity case (declaration survives an earlier raw docstring, which a single-block test would miss); declaration inside the raw block itself; all six forms parse.test_strip_env_declarations— an__Env__section in a raw block strips as a plain one does.Verification
main— identical failure sets. All 14 areipynb-py-convertfailing to build in the dev container; CI installs it, so they run green here.generate_markdown.script_titleverified unaffected (its regex finds the"""after ther, same title either way);navigatorreads already-converted output.Notes for the reviewer
ipynb-py-convert.black-formatted (44 files onmainwould change), so the new code matches surrounding style rather than a formatter.feature/hands-hygiene-leftovers— that branch touchesAGENTS.md,generate_release_notes.py,bin/autohandsand two unrelated tests, so there is zero file overlap and the two can merge in either order.🤖 Generated with Claude Code
https://claude.ai/code/session_01MTjtx5mdituitiyQYFGn2E
Generated by Claude Code