From 04ecff80484ac7e59981485e0d300b3bf1d0623e Mon Sep 17 00:00:00 2001 From: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com> Date: Fri, 4 Sep 2026 23:17:43 -0700 Subject: [PATCH] =?UTF-8?q?contract(operator-surface):=20owner-ratified=20?= =?UTF-8?q?DRAFT=20true-up=20#1=20=E2=80=94=20Core=204=20reaches=20", re.DOTALL) +#: An f-string placeholder naming a bare module-level constant -- the shape +#: `webtrust.py:374` (``) uses to embed its stylesheet. +_NAME_PLACEHOLDER = re.compile(r"\{([A-Za-z_][A-Za-z_0-9]*)\}") + + +def _module_str_constants(path: Path) -> dict[str, tuple[str, int]]: + """Module-level `NAME = "..."` string constants -> (value, line). + + Read by PARSING, never importing -- the same rule the rest of this kit + follows, so the census stays in-process and side-effect free. + """ + out: dict[str, tuple[str, int]] = {} + for node in ast.parse(read(path)).body: + if not isinstance(node, ast.Assign) or not isinstance(node.value, ast.Constant): + continue + if not isinstance(node.value.value, str): + continue + for target in node.targets: + if isinstance(target, ast.Name): + out[target.id] = (node.value.value, node.value.lineno) + return out + + +def style_blocks_outside_token_module() -> list[tuple[str, int, str]]: + """Every `` " + f"lives in a different string literal is INVISIBLE to this census, which " + f"would understate the violation -- fix the matcher, never the count." + ) + for tag in tags: + body = tag.group(1) + tag_line = text.count("\n", 0, tag.start()) + 1 + literal = _NAME_PLACEHOLDER.sub("", body) + if literal.strip(): + out.append((path.name, tag_line, literal)) + for name in _NAME_PLACEHOLDER.findall(body): + resolved = consts.get(name) + if resolved is None: + raise AssertionError( + f"`