Repository navigation
refactor(corekit): give EnumRegistry a bare EnumLookup parent carrying get/get_all (#877) - #906
Conversation
…g get/get_all (#877) `pcapkit/corekit/enum.py` held a single base, so an enumeration wanting only `get`/`get_all` had to inherit `register`, `register_alias`, `register_aliases`, `_extend` and `_unregistered_member` with it -- a mutating contract the owner ruled the closed helper sets must not be handed: "they may subclass a bare base enum from pcapkit.corekit.enum - where EnumRegistry subclasses it for using in the other mutable ones." - `EnumLookup` now carries `get`, `get_all` and a new `_validate_value`, and `EnumRegistry(EnumLookup)` keeps the mutating five. Which tier each method lands on follows the owner's own second thought -- "if it carries `register`, then why not `register_alias`" -- because a base holding both leaves `EnumRegistry` too thin to justify being a second class at all. - `_validate_value` is the range-validation hook the owner asked for. The base accepts everything, so nothing changes for a class that does not override it; `get` calls it immediately before `cls(key)`, and `register` after its duplicate check, so one override guards the lookup and the minting path both. - Both tiers stay plain classes, so `_member_type_` still resolves past them to the enum base and `int`-, `str`- and flag-valued registries are untouched. - Corrected this module's own census, 124 -> 125 registries, and added `TLSKeyLabel` to its str-valued list -- both stale since #890 moved that class from a hand-written helper to a generated registry. Behaviour-preserving, measured rather than asserted: a fingerprint of all 125 registries -- members, lookup tables, `get`/`get_all`/`default` over every member, miss paths, and pickle on all six protocols -- is byte-identical before and after, apart from the MRO and method-resolution strings themselves. Re-parenting the helper enumerations onto the new base is phase 2 of #877 and is deliberately not in this change; auditing each registry's case sensitivity is #903.
|
GOOD TO GO on The hook is not decorative, proven by breaking it three ways — each reverted afterwards: So the five new statements are genuinely pinned, not merely executed. It also built a real Behaviour preservation confirmed independently across all three member shapes, not taken from the author's fingerprint: The 125-registry census independently re-derived by walking #903's boundary respected: no per-registry audit in the diff. Not Merged-tree run (fast-forward, since the base is current Three things flagged from the author's own report, none blocking, all recorded rather than lost:
A merge-order hazard git will not flag. This PR renames Ready for you to merge. I am not merging. |
…issue (#719) - Nine citations in tests/ called a pull request "GitHub issue" (#921, #764, #906, #815, #936, #721, #501, #983) or lumped PR #428 in with issue #425; each now names the right kind. - test_dispatch_default_resolution_unit: issue #425 reported the registry leak and PR #428 fixed it, so the sentence says "reported" and "fixed" instead of crediting the issue with the fix. - Prose only: docstrings and comments, no assertion or logic touched.
Please follow the guide below
make pylint,make mypy,make isort)make testpasses, and a test case covers the changedocs/source/changelog/and regeneratedCHANGELOG.md, if the change is user-visible — N/A -- changelog centralised in docs(changelog): shared 1.5.0 changelog — long-lived, merges last (#610, #616, #617, #618, #620) #657What is the purpose of your pull request?
fix— corrects a defectfeat— adds a featureperf— changes performance, not behaviourrefactor— changes neither behaviour nor performancetest— tests onlydocs— documentation onlyci— workflows or build toolingchore— anything elseDescription of your pull request and other information
Phase 1 of #877, and only phase 1 — re-parenting the helper enumerations onto the new base is phase 2 and is deliberately not here, because it touches files three other changes are currently in.
EnumLookupnow carriesget,get_alland a new_validate_value;EnumRegistry(EnumLookup)keepsregister,register_alias,register_aliases,_extendand_unregistered_member. That split, and the choice not to putregisteron the base, are both the owner's rulings on #877 — the second following his own "if it carriesregister, then why notregister_alias"._validate_valueis the range-validation hook asked for there. The base accepts everything, so nothing changes for a class that does not override it;getcalls it just beforecls(key)andregisterafter its duplicate check.Behaviour-preserving, measured rather than asserted. A fingerprint of all 125 registries — members, lookup tables,
get/get_all/defaultover every member, miss paths, and pickle on all six protocols — is byte-identical before and after, apart from the MRO and method-resolution strings.pcapkit/corekit/enum.pystays at 100% coverage with covered statements rising 62 → 67;pylint,mypyandverminare at exact parity.Also corrected this module's own census — 124 → 125 registries, with
TLSKeyLabeladded to itsstr-valued list — both stale since #890. Per-registry case-sensitivity auditing is #903.