Repository navigation
fix(conventions): --emit-headers --write fills a one-quote docstring, and exits 1 on one it cannot (#785) - #980
Merged
hslee16 merged 1 commit intoNov 13, 2026
Conversation
…te docstring, and exits 1 naming a module it cannot (hslee16#785)
There was a problem hiding this comment.
Gates Passed
3 Quality Gates Passed
See analysis details in CodeScene
Quality Gate Profile: The Bare Minimum
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.
🏛️ Architecture score (archy)Overall: 0.5994 → 0.5994 (-0.0000) ➖ no change
Both scored by this PR's archy, so the delta is the code and not the scorer. Non-blocking; a drop of 0.02 or more overall is flagged. Higher is better. |
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.
Fixes #785.
What was wrong. On a module whose docstring is a one-quote string (
"doc"or'doc'),archy conventions --emit-headers --writewrote nothing, saidwrote 0 header(s)and exited 0, while--checkstayed red and told the user to run that same--write.apply_headersplit the docstring on"""or''', found neither, and returned the source unchanged (if len(body) < 3: return source);_sync_headerscounts a module as written only when the text changed, so the skip was silent.What changed. Both parts of the issue's Expected.
apply_headernow reads the docstring span withtokenize. A single string literal, optionally prefixed (r,u,R,U) or in parentheses, is rebuilt as a triple-quoted literal with the same prefix and quote character. The text between the quotes is kept as written, escapes included, so the human's prose is not rewritten. A second run changes nothing."""doc"""; import os) is kept. A docstring that is not one literal (implicit concatenation"a" "b") raisesValueErrorinstead of returning the source._sync_headersrecords it per module, keeps writing the others, and the command exits 1. Text output names each module under thewroteline;--format jsongains anerrorsobject (module to reason).--writehelp and README.md:219 say it exits 1 and names the module. Thecli_conventionsderived header now listsrun.errorsas a reason it exits 1 (regenerated by--emit-headers --write). The docstring sentence "always exits 0" is docs(cli):archy conventions --helpsays it "always exits 0", but--emit-headers --checkexits 1 #786 and is left to it; when it is fixed,--writebelongs in that sentence too.How it was checked.
tests/test_headers.py: one-quote docstrings across both quote characters and five prefixes, escapes kept as written, parenthesized triple-quoted docstrings, the two refusals, a comment repeating the literal and code after;, and two CLI tests (the issue's fixture through--write,--check,--writeagain; and a refused module beside a good one, text and JSON). Each first asserts its fixture reaches the branch (ast.get_docstringgives the doc, no triple quote in the source), as the issue's Test section asks. With thesrc/changes reverted, 22 of them fail; with the refusal put back toreturn source, 6 fail.uv run pytest, rebased on the current main (c1863e7): 2348 passed, 12 skipped.ruff check(no path),ruff format --check,ty check,archy check .,archy cycles . --strict,archy contracts .,archy conventions . --emit-headers --check: all clean.--emit-headers --writeneither preserves the file's encoding nor re-parses its output, so it can break a module, half-write a tree, or never converge #783 (encoding and re-parse on the same write path) is not touched.This pull request was written by Nightlab, an AI agent (https://github.com/nightlab-agent). Before opening it, Nightlab ran
/nightlab/prs/drill-archy-785/.venv/bin/python -m pytest -q -p no:cacheprovider tests/test_headers.pyon this branch and it passed. If AI-written contributions are not welcome here, close it and Nightlab will not open another pull request on this repository.