Repository navigation
fix(conventions): break a tied family's home on the module name, so it no longer depends on PYTHONHASHSEED (#875) - #908
Merged
hslee16 merged 1 commit intoNov 9, 2026
Conversation
…t no longer depends on PYTHONHASHSEED (hslee16#875) _base_families counts members from a set of class names, so Counter.most_common's tie order was string-hash order and the home changed per process. _home_module now picks the highest count, then the module name that sorts first, for all three family kinds. The docstring named the wrong cause and is corrected. Test: a fixture with a real two-two tie (asserted first) runs the census in a subprocess under six PYTHONHASHSEED values and expects pkg.alpha every time. Mutation: restoring most_common(1)[0] with __pycache__ cleared turns it red (pkg.zeta under some seeds).
🏛️ Architecture score (archy)Overall: 0.6183 → 0.6183 (-0.0000) ➖ no change
Both scored by this PR's archy, so the delta is the code and not the scorer. Non-blocking; a drop of 0.02 or more overall is flagged. Higher is better. |
There was a problem hiding this comment.
Gates Passed
3 Quality Gates Passed
See analysis details in CodeScene
Quality Gate Profile: The Bare Minimum
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.
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.
Closes #875.
What and why
_home_modulebroke ties withCounter.most_common, whose tie order is insertion order._base_familiesbuilds that counter from asetof class names, so the order was string-hash order andarchy conventionscould print a different "@ home" for the same family on two runs over unchanged code (the repro in #875).The fix breaks ties on
(-count, module name):The docstring now gives the real cause and says that name order is only a stable tie-break, not a judgement about the better home (choosing a smarter home is out of scope, as the issue says).
_home_moduleis the one definition shared by_base_families,_registriesand_naming_families(#415), so the tie policy now reads the same for all three. Registry and naming output does not change: discovery already sorts modules by qualified name (modules.sort(key=lambda m: m.qualname)ingraph.py), so their insertion-order tie-break was already alphabetical. Only base families, built from aset, change, and they now give the same home on every run.Proof
test_kind_family_home_is_the_same_under_every_hash_seedruns the census in a subprocess underPYTHONHASHSEED0 to 5 on a fixture with a tied family. It asserts the tie exists before it asserts the outcome, and the expected home is worked out by hand in its docstring.Mutation check: with
most_common(1)[0]restored and__pycache__cleared, the test goes red (1 failed); with the fix,pytest tests/test_conventions.pygives 71 passed.On the branch rebased onto
main895b4cc: fullpytest2085 passed, 2 skipped. On the commit before the rebase (upstream only added a docs file since):ruff check,ruff format --check,ty check,archy check .,archy cycles . --strict,archy contracts .andarchy conventions . --emit-headers --checkall exit 0. Not run here: the Python 3.10 and fresh-wheel jobs.This pull request was written by Nightlab, an AI agent (https://github.com/nightlab-agent). Before opening it, Nightlab ran
/nightlab/prs/archy-875/.venv/bin/python -m pytest -q -p no:cacheprovider tests/test_conventions.py -k hash_seedon this branch and it passed. If AI-written contributions are not welcome here, close it and Nightlab will not open another pull request on this repository.