fix(corekit): fall EnumRegistry.get() back to a str key's value (#860) - #863
Conversation
|
NEEDS CHANGES on
Latent today and not introduced here — on Everything else confirmed, including what the review tried hardest to break: both halves of the defect reproduced independently on both trees; Two corrections to my own earlier statements. I said five |
1e90155 to
6cbe5ea
Compare
|
Round 2 pushed — new head The added paragraph carries the caveat the review asked for, and puts it on the PR's own new prose rather than editing the pre-existing sentence: a declared-but-unassigned value is invisible to the Correction to my previous comment. I wrote that "the PR's 'two pre-existing mypy findings' is one". The PR body never said two — line 52 reads "mypy's one pre-existing ... finding", singular. The "two" was in the agent's hand-back report to me, not in this PR, and I misattributed it. The substance stands: one finding, Also taken: the 69 tests still pass under plain |
|
NEEDS CHANGES on
I verified it and it is wider than the review said. The reviewer scoped this to So Everything else in round 3 confirmed, and the "prose only" claim was proved mechanically rather than taken from the diff: both files parsed at both revisions, docstrings stripped, ASTs identical, and the non-docstring string constants identical too (38 in One non-blocking suggestion from the review I agree with: add a five-word qualifier to the unconditional promise at |
6cbe5ea to
e36ab4d
Compare
|
Round 3 pushed — head The clause is correctly scoped now ( The optional qualifier was taken too —
Label back to |
- EnumRegistry.get()'s str branch only tried cls._member_map_[key] (a name lookup), so a StrEnum registry's value that was not also a name raised KeyError instead of resolving -- unlike the int/value path. A supplied default compounded this: it overrode a good value match it never got the chance to try. - Add a plain _value2member_map_ lookup as the fallback, after the name lookup and before default/raise. Name still wins when a string is both a name and a different member's value. - Deliberately not cls(key): FEATCode._missing_ (pcapkit/const/ftp/ command.py) mints directly via extend_enum for any unrecognised string, so routing the fallback through the constructor would let a failed name lookup mint a permanent member the moment #860's step 2 converts such a registry onto this base. A dict lookup never reaches _missing_, so it cannot mint. - Extends tests/const/test_const_registry_protocol.py: the defect itself, name-first precedence, the default-vs-value ordering, an IntFlag get() matrix parity pin, and a no-mint regression test that mirrors FEATCode's _missing_ shape. Built and tested: tests/const, tests/vendor, tests/test_tier_guard.py all green (372 passed). mypy's one pre-existing "Self" has no attribute "name" finding on this file is unchanged.
e36ab4d to
216369e
Compare
|
GOOD TO GO — round-4 cross-review (opus, author sonnet) on The corrected clause discharges the round-3 finding. The reviewer ran the "exactly as it already did" half on both trees, five cases diffed, and four are byte-identical — including case A, the one the clause is about, which mints on both trees. So "can mint there just the same" is confirmed against Its section-2 reasoning went stale mid-flight, in a way that strengthens the verdict. It argued that fixing The two nits, both taken:
"Prose only" proved mechanically again, not read off the diff: both revisions parsed, docstrings stripped, ASTs identical, non-docstring string constants identical (38 in |
Please follow the guide below
make pylint,make mypy,make isort)make testpasses, and a test case covers the changeWhat is the purpose of your pull request?
fix— corrects a defectDescription of your pull request and other information
Step 1 of #860 only: fixes
EnumRegistry.get'sstr-key dispatch so aStrEnumregistry can resolve a key that is a valid value but not aname. Step 2 (converting the 16 bespoke registries) is a separate,
still-open change.
The defect.
get'sstrbranch tried onlycls._member_map_[key](a name lookup) and, on a miss, either raised or returned
cls(default)— it never tried the value path at all. On a synthetic
EnumRegistry+StrEnumfixture,_Str.get('known-value')raisedKeyErroreventhough
_Str('known-value')resolved fine. A supplieddefaultcompounded it: it overrode a good value match the code never tried.
The fix. After the name lookup misses, fall back to a plain
_value2member_map_dict lookup before consultingdefault. Deliberatelynot
cls(key):FEATCode._missing_(pcapkit/const/ftp/command.py:43)mints directly via
extend_enumfor any unrecognised string — confirmedby reproducing its shape in a test — so routing the fallback through the
constructor would let a failed name lookup mint a permanent member the
moment step 2 converts a registry like it onto this base. A dict lookup
never reaches
_missing_, so it cannot mint, on any registry.Name still wins when a string is both a name and a different member's
value — matches today's behaviour for names that already resolve, pinned
with its own test.
Not touched: the
IntEnum/IntFlagnon-strpath — its own get()matrix (valid value/name, missing name/value with and without default, a
key that is neither
intnorstr) is measured identical before andafter, on both an
IntEnum(TransType) and anIntFlag(
HandoverACKFlag). Nothing underpcapkit/const/orpcapkit/vendor/.Breaking? No — this widens: a call that raised
KeyErrorbefore nowresolves. No caller that got a correct result before gets a different one
now.
Build/test:
tests/const,tests/vendor,tests/test_tier_guard.pyallgreen (372 passed, re-derived under plain
unittesttoo). mypy's onepre-existing
"Self" has no attribute "name"finding on this file isunchanged.