Repository navigation
docs(lang): say that mixed_segment is filled only by the segment scan - #1123
Merged
NandhaKishorM merged 2 commits intoOct 12, 2026
Merged
Conversation
analyse() documents mixed_segment as "the line or field that made a mostly English state non-English", but the per-value read added for NandhaKishorM#384 sets language and is_english from a local and never writes the value back, so a state flipped non-English past the 4,000-character segment cap reports mixed_segment None while still naming the language. The docstring now states which of the two reads is reporting, since no caller can tell the provenances apart from the result alone.
Three checks at the seam: _non_english_segment returns None once a long English first field has spent the cumulative 4,000-character budget, _leaf_non_english still names the foreign field's language, and analyse reports it with mixed_segment None. Mutating the cumulative guard (laya/lang.py:655-657) to a per-leaf budget turns both new mixed_segment checks red; running main's suite under the same mutant fails only its own cap check, so these two are the net-new witnesses. tests/test_router.py goes 804 -> 807 checks.
Owner
|
Merged. The distinction is real and invisible from the outside: The test earns its place by constructing the budget exhaustion rather than asserting the current behaviour: 5,000 English characters in the first leaf spend |
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.
What
analyse()advertisesmixed_segmentas "the line or field that made a mostly English statenon-English, else None", but two different reads can flip a state non-English and only one of them
reports which line it was. This says so in the docstring and leaves three checks at that seam.
laya/lang.pymoves by 4 added / 2 removed lines of docstring and nothing else; no behaviour changesand no prediction differs.
Why
_non_english_segment(laya/lang.py:642), is the read that fills it:result["mixed_segment"] = mixedatlaya/lang.py:841._leaf_non_english(laya/lang.py:749), setslanguage,is_englishandlanguage_undecidedoff its localbestdict and never writes the offending textback (
laya/lang.py:859-861). Its result dict comes from_analyse_text, which always carriesmixed_segment: None.So a foreign field sitting past the scan's cumulative 4,000-character budget is named by
languageandreported with
mixed_segmentstillNone. A caller cannot tell the two provenances apart from theresult, and the docstring described only one of them. The fix is prose plus a test that makes the
difference visible; changing the behaviour instead would invent a second meaning for a field the router's
reason string already reads.
How it was verified
tests/test_router.pyonmainatc4a805b5: 804 passed, 0 failed. On this branch:807 passed, 0 failed.
scripts/test_suites.pyon this branch: 497 passed, 1 skipped -- all 87 suites passed, rc=0.ruff:All checks passed!, rc=0.compileall: rc=0.Mutation witness. Replacing the scan's cumulative budget with a per-leaf one --
if seen >= max_chars: return Noneatlaya/lang.py:655-656toif False:and the slice at:657toseg = seg[:max_chars]--turns three checks red:
mixed/segment check reads at most the capis main's own check, so I ranmain'stests/test_router.pyagainst the same mutant: 803 passed, 1 failed -- only the cap check. The two
mixed_segmentchecksabove are therefore net-new witnesses, not a restatement of an existing one. The converse detail is worth
noting: mutating only the slice line, leaving the stop, keeps the branch green at 807, because with a
5,000-character first field the stop is what ends the scan. Both lines have to move for the budget to
become per-leaf.
The middle check's label was proved, not assumed. It claims the per-value read is what names the
language. Printed from the branch for
{"note": <5,000 English chars>, "body": <German line>}:state_text(state)returns exactly 4000 characters and does not contain the German body at all;_analyse_texton it giveslanguage 'en', is_english True;_leaf_non_english(body)giveslanguage 'de';_non_english_segment(state)givesNone;analyse(state)giveslanguage 'de', is_english False, mixed_segment None. The per-value read is the only one that saw thefield, which is the case the docstring now names.
Deconfliction. Four open PRs touch these two files: #1089 (
tests/test_router.py -562,7), #600(
laya/lang.pyup to-587,11,tests/test_router.py -572,16), #286 (laya/lang.pyup to-587,9),and #91 (
laya/lang.pyup to-164,18,tests/test_router.pyup to-219,7). My hunks arelaya/lang.py @@ -809,8,tests/test_router.py @@ -9,6and@@ -532,6, and the block is placed before#1089's region rather than inside it. Rebased on
c4a805b5, on which neither file has changed since68804629. The diff was scanned for credentials and for absolute local paths: no matches (rc=1 from thepattern scan).
Checklist
mainFixes: no open issue. Found while reading
analyse's docstring against the two reads it describes. Thepublic API does not change, so no
docs/page needed editing.