Repository navigation
Simplify the 4i choice compile and reading-files code (#754) - #1001
Merged
Merged
Conversation
One strict-choice predicate: _reading_index.strict_kept is the filter strict_pool, _lexicon._chosen_pool and _ReadingFiles.languages each spelled out, and chosen_readings the filter-then-choose that compile_choice and the per-word path share. Lexicon._pool reads through _ReadingFiles.pool(), which holds the same base, log and choice. _compiled_for's nested arms are flattened; _reading_files is sized as _built; _rechosen_masks loads the default's masks only where it reads them; _unwritten reads the unwritten values from ReadingProperties instead of restating them; a __setstate__ comment said no field was marked ADDED_IN. No behaviour or message change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
A
/simplifypass over the code the 4i series (#989, #991, #992, #997) added for #754. It is a quality pass only, with no behaviour, message, signature, repr or pickle change.The 2.x translation code (
_target_readings,_inert_dropped/_MARKER_READ_WITH,_edits_toward,_translation,_refusal's translation arms,_changed, the 2.x pickle load) is deliberately left alone. It is migration scaffolding, deprecated in 3.0 and deleted in 3.1. The findings that apply only there are listed at the end, for the 3.1 deletion.Line delta
nameparser/_lexicon.pynameparser/_reading_index.py_parser.pyand_pipeline/_assemble.pyare unchanged.What was folded or removed, and why
_reading_index.strict_pool,_lexicon._chosen_pool, and the per-word path of_ReadingFiles.languages._reading_index.strict_kept(readings, chosen)is now the one copy.chosen_readings(readings, chosen, strict)is that filter followed bychoose. Bothcompile_choiceand_ReadingFiles.languagesread through it.Reading.languagespath was exact only as long as it matched the compile by hand.Lexicon._poolreads through_ReadingFiles.pool(). The two held the same four values (base, log, choice, strict) and the same no-log/log branch._ReadingFiles.languages' log arm calls the same method._compiled_foris flattened. The three nested arms, including anelifthat testedbaseagain, are now two flat guards with the same arms in the same order._reading_filesusesmaxsize=128, as_builtdoes. With 64 it evicted first, so two equal lexicons built after an eviction stopped sharing assemble's memo. Results were correct either way._rechosen_masksloads the default's masks only in the arm that reads them._unwrittenreads the unwritten values from_reading_index.ReadingProperties. Those areacronym,addressesandflag. Its docstring already said it did, but the code restated them. The new version is checked equal to the old one over every kind × property.Lexicon.__setstate__. It said no field was marked_ADDED_IN("none yet"), but_languagesand_strictboth are.Considered and skipped
_ReadingFiles, so a memo miss never looks up or rebuilds_built. Assemble's 4096-entry_languagesmemo keys on the_ReadingFiles, so each cached object would pin a whole pool alive. That is an unbounded memory cost traded for a miss path that is rare._with_packs' two mask branches into one_rechosen_maskscall. Aparser_forthat chooses no language would then load the reading index, which it does not do today._check_base's validation of a snapshot base. A snapshot base is reached only from another release's pickle._failed_layer,_clashes_unchosenandparser_for's three-statestrict. Nothing simpler keeps the messages, and folding the twostrictchecks would change which error wins when an argument is bad in two ways.Candidate needing a decision
_MARKER_READ_WITH'safter_given_titlesrow liststitlesalone, where its title siblings also listtitles_ambiguous.Lexicon.default().add("dean", kind="salutation", after_given=True)compilesdeanintoafter_given_titlesandtitles_ambiguous, and_inert_droppedthen drops it, against its docstring.Left for the 3.1 deletion
These are findings that only make sense inside the translation code:
_TITLE_FIELDS,_ACRONYM_FIELDS,_WORD_FIELDS,_PARTICLE_FIELDSand an inline conjunction pair) can be derived from_MARKER_READ_WITH. They were checked equal._target_readings' pop-then-set marker properties could be a table._by_kindis the first element of each list_props_by_kindbuilds._translationand_translated_2xshare a "compared sets" step (titles_ambiguous - titles, then_inert_dropped)._refusalcould take the op rather than string-sniffingwhere._translation'sprefixdefault is never used._shown_valuerepeats_prop_value's property list.Gates
All of these were run on the final tree and pass:
uv run pytest: 34,734 passed. This includestest_snapshot.py, unchanged, and the 2.8 and 4i-b pickle rows.uv run pytest -n0 -m serial: 42 passed, so the frame baseline holds.uv run --python 3.15 pytest: passes.uv run mypyanduv run ruff check: clean.sphinx-build -b doctest docsandpython -m doctest README.rst: clean.tools/differential/cldr_agreement.py: every record matches.🤖 Generated with Claude Code