Skip to content

Correct the AGENTS files, READMEs and pickle notes, and hold every pack to the layering rule - #1438

Merged
derek73 merged 3 commits into
masterfrom
docs/sweep-guidance
Nov 16, 2026
Merged

derek73 merged 3 commits into
masterfrom
docs/sweep-guidance

Conversation

@derek73

@derek73 derek73 commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Section D of the 3.1 release checklist's stale-prose sweep (root AGENTS.md, step 0), measured on master f510237 and re-run on this branch. No parse behaviour changes: where prose and the tree disagreed, the prose now says what the tree does. The one change to code is the layering test, plus a new tool and its test.

The layering guard (fixed)

Root AGENTS.md said pack modules import _locale/_lexicon/_policy/_types only, and that tests/v2/test_layering.py enforces it. But ALLOWED keyed only four packs (ja, ru, tr_az, zh) and _es_given_names.py, so 17 packs and _es_ar_given_names.py were checked by nothing. Now:

  • _locale_rules() gives every file in nameparser/locales/ except __init__.py a default rule. A pack may import the four base modules plus its own private data modules. A data module belongs to the pack with the longest stem its name begins with, so _es_ar_given_names belongs to es_ar, not es. A data module imports nothing internal. No pack is keyed by hand.
  • test_every_locales_module_is_checked is the locales/ twin of the pipeline completeness check. It has a floor so that an empty glob cannot pass.
  • New rows: a pack may import its own data module only (four cases), and the pack rule refuses the pipeline, the parser, config data, another pack and the reading index.
  • The AGENTS.md sentence now says exactly what the test enforces, including the data-module imports.

To show the guard bites, I added from nameparser._pipeline._vocab import is_initial to locales/hr.py (a pack master's test never checked) in a scratch worktree. With the new test:

E   AssertionError: locales/hr.py imports nameparser._pipeline._vocab, which the layering contract forbids (allowed prefixes: ('nameparser._lexicon', 'nameparser._locale', 'nameparser._policy', 'nameparser._types'))
FAILED tests/v2/test_layering.py::test_layering_contract
1 failed, 282 deselected

With master's test, the same mutation gives 1 passed.

Review round 1 (second commit)

  • The walker read node.module alone, so it missed relative imports: from .. import _parser in a pack passed, and _suggest.py, which imports only relatively, was checked by nothing. It now resolves node.level against the module's package. New tests cover each relative form, a planted pack violation and a probe that _suggest.py yields its imports. With relative imports resolved there are 0 current violations, and _suggest.py's real imports all fit its existing row. The same mutation in a scratch worktree, appending from .. import _parser to locales/pt.py, now fails the contract.
  • The locales/ completeness check now lists modules through pkgutil rather than the rule's own glob, and holds each to its kind's rule.
  • The stage_reads tests now pin a read that only the row's policy causes (post_rules → P.name_order under two_family_names), and check that the traced fold assembles exactly what Parser.parse gives on six rows.
  • An AGENTS.md attribution naming a person is reworded.
  • The checklist describes the Reads: convention without quoting classify's header, which Correct stale docstrings, comments and stage headers #1439 corrects.

The Reads: check (kept as a tool)

The auditor's trace was sound. It wraps the parse's Lexicon, its _sets and its Policy in proxies that record each attribute read, and charges each read to the stage that is running. Because it watches reads happen at runtime, it sees the reads that the checklist's grep cannot: reads through the 20 sets = lexicon._sets aliases in _pipeline/, and reads through _vocab/_pieces helpers. For example, assign reads the suffix sets through is_suffix_lenient, and classify reads honorific_tails and saint_particles.

I kept it as tools/stage_reads.py (--stage NAME for one stage), with these changes from the draft:

  • typed, lint-clean, with a CLI
  • _comma.decide's recursion labelled once
  • the wrapper restored on exit
  • it runs all 2,392 case rows in under a second

Its limits are stated in its docstring: it cannot see a read that no case row reaches, and it charges a read made inside a Lexicon method to that method. tests/v2/test_stage_reads_tool.py loads it by path, as test_docs_scan_tool.py does, and pins:

  • a read made through a helper (assign → L.suffix_words, which _assign.py never spells)
  • the decision's reads charged apart from the stage's
  • policy reads
  • the wrapper restored and the parse unchanged
  • the CLI error

The checklist bullet now says what the grep misses and names the command. I took out its quote of classify's Reads: line, which another sweep PR corrects.

Findings (section D)

Finding Result
Root AGENTS.md: pack layering sentence / guard gap fixed (above)
Root AGENTS.md: repr example Lexicon(default + titles: +2) fixed → title: +2
Root AGENTS.md: U.S. Grant given 'U.S.' fixed → given 'U.', middle 'S.', given_names 'U.S.'
Root AGENTS.md: "a non-stage _pipeline/ module says so in its first line" fixed: _assemble/_comma say "Not a stage"; _vocab/_pieces/_state name themselves helpers or state. Also fixed a stray parenthesis in the same sentence.
Root AGENTS.md Tests gotcha: "emptied hu.toml's familiar readings" fixed: #1379 gave hu.toml zsuzsa again ('hu' in tags() is False, so hu.toml is a shipped witness again); the sentence now says so.
Root AGENTS.md step 0: Reads: grep blind spots fixed (above)
Root AGENTS.md step 8: maintenance-branch release fixed: a release cut from a maintenance branch needs DEFAULT_BASELINE set on master too
compare.py DEFAULT_BASELINE = "3.0.0" fixed → "3.0.1". No test pins the value; the README says "the last release" without a number. test_differential.py's "against 3.0.0" is a dated measurement and stays.
nameparser/AGENTS.md, _pipeline/AGENTS.md, vocab/AGENTS.md: TITLES ∩ particles_ambiguous lacking տեր fixed: each now gives today's set with the date and the one-liner
vocab/README.md: "one dict" fixed → five dicts, named
vocab/README.md: bon/dí keep the generic particle kind fixed: #766 took their particle readings away (no generic particle reading is left in any file)
vocab/README.md: D.R. Judge Smith keeps given D.R. fixed → given 'D.', middle 'R. Judge', no title
CONTRIBUTING.md: "thirteen sources", "about 30 million records", "about 12 GB" fixed: SOURCES has 16. The fetched corpora's meta.json records sum to 8,839,814, so the text now says "about 9 million", dated. The cache measures 12G, which still holds.
differential README: module list missing three fixed: added local_uit, local_vnassembly, local_parliaments
differential README: "Recompute" heredoc raised fixed (reads Parser().lexicon._sets). It now prints 5 of 17 markers and 13 of 28 tails. The prose said 8 of 15 tails; it now gives the new figures with the 2026-08-26 ones as history. "ships 17 entries" is now dated, and Lexicon.maiden_markers (internal) is no longer named.
differential README: LOCALE_FILES/NATIVE_LABELS lists short fixed against cldr_agreement.py
differential README: Md. a title by shape fixed: a title until #1383 made it the given name written short
differential README: "as locales.NE is" (choice only) fixed: "was until #1254 gave it initials_as_family"
differential README: surname2 "filled by two_family_names only" (two places) fixed: under locales.ZH, a Han surname pair fills it too (rules/W5); the snapshot and record are the default's
differential README: MARIA DE SA reads SA as a credential fixed: past tense, until #857
differential README: harness proof with two --set flags fixed: adds _MIN_RUN_NAMES, as root AGENTS.md has it. The 0%-on-2026-11-15 figure is marked as measured with the first two (I did not re-run it). Also added orcid-famcaps-ea and the per-population East Slavic / initials_as_family output.
differential README: matching vocabulary omits spelling fixed
differential README: local_agreement box list omits patentsview-inventors fixed (from FIELDED)
differential README: undated "1 of the 1,315,051 distinct spellings" fixed: dated to jrc-names' fetch of 2026-10-24 (the commit that added it, #865)
differential README: stray "),." fixed
differential README: two attributions naming a person fixed → "(decided 2026-10-16)"
release_log pickle bullet fixed: one limit sentence (a 3.1 Lexicon, Parser, pack or Policy does not load under 3.0.x) and a link to migrate's Pickles section, which holds the rest measured below
migrate.rst Pickles fixed: one table row for 3.1 pickles under 3.0, the 3.0 row's caveat, and a "Between 3.0 and 3.1" subsection with the caveats as short text

Pickle measurements

The 3.0.1 wheel was run from a scratch dir with PYTHONSAFEPATH=1 uv run --isolated --no-project --with 'nameparser==3.0.1'. The script asserts that nameparser.__file__ is outside the checkout; it was ~/.cache/uv/archive-v0/.../site-packages/nameparser. The tree side asserts the reverse.

3.0.1 pickles loaded by the tree:

loads   ambiguity, lexicon_default, pack_ES, pack_NE, parsed_name, parser_default, parser_for_NE, patch_order, policy_default
REFUSED lexicon_tatweel ValueError _edits holds an edit not in canonical form; build a Lexicon's log with add() and remove()
REFUSED parser_tatweel  ValueError (same)

(Lexicon.default().add("محمـد", kind="given"))

Tree pickles loaded by 3.0.1:

loads   ambiguity, parsed_name
REFUSED lexicon_default / lexicon_tatweel / parser_default / parser_for_NE / parser_tatweel  ValueError a Lexicon snapshot gives '1stlt''s military reading the property 'same_as', which a military reading does not take in this release
REFUSED pack_ES / pack_NE / patch_order  ValueError incompatible PolicyPatch pickle: missing fields: none; unexpected fields: capitals_as_family, initials_as_family
REFUSED policy_default   ValueError incompatible Policy pickle: ... unexpected fields: capitals_as_family, initials_as_family
REFUSED policy_cyrillic  ValueError 'cyrillic' is not a valid Script

A 3.0.1 Parser() loaded in the tree, compared with a fresh one:

  • Md. Rahim Uddin: title 'Md.' vs given 'Md.'
  • นายสมชาย ใจดี: given 'นายสมชาย' vs title 'นาย', given 'สมชาย'
  • Bill Smith/William Smith, accepting every outcome: inconsistent, conflict vs consistent, familiar-form
  • A pickled locales.NE reads Ram Bahadur B K as middle 'Bahadur B', family 'K', against a fresh pack's family 'B K'.

Examples in the changed AGENTS/README lines, run on this branch

AGENTS repr: Lexicon(default + title: +2)
AGENTS U.S. Grant: U. | S. | given_names U.S.
AGENTS hu in tags(): False
AGENTS compare.DEFAULT_BASELINE: 3.0.1
nested AGENTS titles & particles_ambiguous: ['freiherr', 'fürst', 'graf', 'gräfin', 'prinz', 'st', 'տեր']
vocab/AGENTS titles & particles: ['freiherr', 'fürst', 'graf', 'gräfin', 'prinz', 'st', 'տեր'] | particles & suffix_acronyms: ['do', 'mc', 'vd']
vocab/README D.R. Judge Smith: '' D. | R. Judge | given_names D.R. Judge
'Md. Rahim Uddin'                  {'given': 'Md.', 'middle': 'Rahim', 'family': 'Uddin'}
'MARIA DE SA'                      {'given': 'MARIA', 'family': 'DE SA'}
'MARIA DE SÁ'                      {'given': 'MARIA', 'family': 'DE SÁ'}
'Jane Smith (Jones)'               {'given': 'Jane', 'family': 'Smith', 'nickname': 'Jones'}
'Jane Smith née Jones'             {'given': 'Jane', 'family': 'Smith', 'maiden': 'Jones'}
'Jane Smith (née Jones)'           {'given': 'Jane', 'family': 'Smith', 'maiden': 'Jones'}
'Maria Kowalska (z domu)'          {'given': 'Maria', 'family': 'Kowalska', 'nickname': 'z domu'}
'Jane Smith (Nee)'                 {'given': 'Jane', 'family': 'Smith', 'nickname': 'Nee'}
'Jane Smith (Jones)'               {'given': 'Jane', 'family': 'Smith', 'maiden': 'Jones'}
'王李小明'                             {'given': '小明', 'family': '王李'}
  surname2: '李' default: ''
maiden markers shipped: 17

Verification

  • uv run pytest: 49811 passed, 45 skipped, 3 xfailed (after round 1)
  • uv run pytest -n0 -m serial: 38 passed
  • uv run mypy, uv run ruff check: clean
  • sphinx-build -b doctest and -b html: no output
  • tools/docs_scan.py migrate.rst: 0 findings

Left for others (not my files)

  • nameparser/locales/__init__.py's docstring still says packs import "_locale/_lexicon/_policy/_types only", without the data module.
  • _reading_index.tags()'s docstring says "no shipped file has that shape at present". hu.toml now has that shape (one familiar reading only).

🤖 Generated with Claude Code

…ck to the layering rule

The 3.1 stale-prose sweep's section D. tests/v2/test_layering.py now
checks every module in nameparser/locales/ by a default rule (the four
base modules plus the pack's own private data module; a data module
imports nothing), with a completeness check over locales/ like the
pipeline's; until now 17 packs and _es_ar_given_names.py were checked by
nothing. tools/stage_reads.py traces the Lexicon and Policy reads of each
stage over the case table, which the release checklist's Reads: grep
cannot see through aliases and helpers. compare.py's baseline moves to
3.0.1. The prose corrections are listed in the PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@derek73 derek73 added this to the 3.1 milestone Nov 16, 2026
@derek73 derek73 added docs Documentation fixes and updates tests labels Nov 16, 2026
@derek73 derek73 self-assigned this Nov 16, 2026
derek73 and others added 2 commits November 16, 2026 02:49
PR #1439 corrects classify's Reads: line, so the checklist describes the
convention rather than quoting which fields that line excepts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tests

The import walker recorded node.module alone, so a relative import was
dropped or recorded as nothing: a pack writing `from .. import _parser`
passed, and _suggest.py, which imports only relatively, was checked by
nothing. It now resolves node.level against the module's package, with
rows for each form, a planted pack violation and a reachability probe on
_suggest.py; the contract finds no current violation with them resolved.
The locales completeness check lists the folder through pkgutil rather
than the glob the rule uses, and holds each module to its kind's rule.
stage_reads' tests pin a read only the row's policy causes and that the
traced fold assembles what Parser.parse gives. The release-log pickle
bullet is trimmed to its index form, and an attribution naming a person
in AGENTS.md is reworded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@derek73
derek73 merged commit 5b5f7aa into master Nov 16, 2026
14 checks passed
@derek73
derek73 deleted the docs/sweep-guidance branch November 16, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation fixes and updates tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant