Skip to content

maintenance: raw-string the LaTeX-carrying docstrings - #492

Merged
Jammy2211 merged 1 commit into
mainfrom
claude/latex-raw-string-docstrings-9h4ine
Aug 20, 2026
Merged

maintenance: raw-string the LaTeX-carrying docstrings#492
Jammy2211 merged 1 commit into
mainfrom
claude/latex-raw-string-docstrings-9h4ine

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Part of #491 — the largest of six independent, prose-only PRs (one per workspace repo). No API surface, so no cross-repo merge ordering.

Non-raw docstrings containing LaTeX are corrupted by Python's escape handling, in two classes — and only one of them is visible:

what it is diagnostic
warned \s, \l, \[ — escapes Python does not recognise SyntaxWarning per compile; slated to become SyntaxError
silent \t in \theta, \f in \frac, \r in \rm none at all — the value is simply corrupted

83 literals across 17 files get the r prefix. The 17 files and 80 warnings match the independent 2026-08-09 measurement exactly. Prose is untouched — only the delimiter gains an r.

Verification

  • Baseline regeneration is a no-op — the generator was run before editing and left the tree clean, so generator noise cannot fake the gate below.
  • Runtime values: 61 corruptions repaired, 0 other changes. Every changed literal's value was compared HEAD vs worktree; the prefix may only ever remove corruption. This is the check that catches real mistakes — the regeneration gate structurally cannot, because the generator reads source text, not runtime values.
  • Regenerated with autohands: notebooks/, markdown/, llms-full.txt and workspace_index.json are all byte-identical — the diff-empty gate passes exactly.
  • All 57 __Env__ declarations in this repo re-read identically through read_env_declaration, byte-compared before and after.

That last check is the one that matters here. Four of the raw-stringed files carry __Env__:

scripts/imaging/features/advanced/potential_correction/likelihood_function.py
scripts/imaging/features/advanced/potential_correction/start_here.py
scripts/interferometer/features/advanced/potential_correction/likelihood_function.py
scripts/interferometer/features/advanced/potential_correction/start_here.py

Before PyAutoHands#251, an r""" opener made read_env_declaration return None — silently — which would have rerouted these scripts' smoke env profile with no error anywhere. These four files exercise that fix end to end.

Known residue

scripts/group/likelihood_function.py keeps 2 warnings + 1 silent hit. Three of its docstrings use the double-backslash convention ($\\theta$, \\frac, \\vec) mixed with a few single-backslash macros. Adding r would double the already-correct escapes and change the rendered LaTeX; fixing it properly means un-doubling 18 backslashes, which is a prose edit this task explicitly excludes. It needs a decision on which convention the file should use — worth a follow-up rather than a guess here. The unambiguous literals in that file were still fixed (4 warned → 2, 3 silent → 1).

Also left alone: already-escaped \\ anywhere, real newlines in print(), and dataset/cluster/a2744/prep.py:38 where line.split("\t") is a genuine TSV tab.

The prefix was applied only where every backslash in the literal sits in a LaTeX context ($…$, \(…\), \[…\], \begin{}…\end{}, or a markdown code span), with an absolute veto on \\, escaped quotes and numeric escapes regardless of context. Four docstrings with unbalanced or malformed delimiters were read in full and prefixed by hand; their delimiters were left exactly as found.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MTjtx5mdituitiyQYFGn2E


Generated by Claude Code

Non-raw docstrings containing LaTeX are corrupted by Python's escape handling.
Two distinct failure classes, and only the first is visible:

  warned  `\s`, `\l`, `\[` ... escapes Python does NOT recognise. It leaves
          them literal but emits SyntaxWarning on every compile/import, and
          they are slated to become a SyntaxError.
  silent  `\t` in `\theta`, `\f` in `\frac`, `\r` in `\rm`, `\b` in `\beta`.
          Escapes Python DOES recognise: the value is corrupted with NO
          diagnostic at all. `\theta_E` was literally TAB + "heta_E".

83 literals across 17 files get the `r` prefix. Both sweeps now return zero.

Verified, not assumed:
- Runtime values: 61 corruptions repaired, 0 other changes. Every changed
  literal's value was compared HEAD vs worktree; the prefix may only ever
  REMOVE corruption, never alter a string otherwise.
- Regenerated with autohands: notebooks/, markdown/, llms-full.txt and workspace_index.json are ALL byte-identical -- the diff-empty gate passes exactly.
- All 57 `__Env__` declarations in the repo re-read IDENTICALLY after the change
  (read_env_declaration, byte-compared before/after). This is the check that
  matters here: four of the raw-stringed files carry `__Env__`, and before
  PyAutoHands#251 an `r"""` opener made that function return None and silently
  reroute the script's smoke env profile.

KNOWN RESIDUE -- scripts/group/likelihood_function.py keeps 2 warnings + 1 silent
hit. Three of its docstrings use the DOUBLE-backslash convention (`$\\theta$`,
`\\frac`, `\\vec`) mixed with a few single-backslash macros. Adding `r` there
would double the already-correct escapes and change the rendered LaTeX; fixing
it properly means un-doubling 18 backslashes, which is a prose edit this task
explicitly excludes. Left for a follow-up that decides the convention. The
literals in that file that were unambiguous were still fixed (4 warned -> 2,
3 silent -> 1).

Prose is untouched -- only the delimiter gains an `r`. Deliberate escapes were
left alone (real newlines in print(), already-escaped LaTeX line breaks): the
prefix was applied only where every backslash sits in a LaTeX context.
@Jammy2211
Jammy2211 merged commit 01f1b18 into main Aug 20, 2026
6 checks passed
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