Repository navigation
fix(const): make every registry's register reject what its get rejects (#1816) - #1823
Merged
Merged
Conversation
Owner
Author
|
Verdict: NEEDS CHANGES at
Required: |
#1816) EnumRegistry.register routes a new value through _validate_value, but only AppType overrode that hook, so Hardware.register(70000, 'x') minted a member that Hardware.get(70000) then returned, although get refuses the value. - Every vendor template emits a _validate_value override with the check it already writes at the top of _missing_, raising EnumValueError with the same message: the crawler's FLAG, or a bespoke template's own range (0-999 for StatusCode and ReturnCode, 0-9 for ResponseKind and GroupingInformation, str for the string-valued ones). TLSKeyLabel and ExtensionHeader have no _missing_, so they check the member type and the 8-bit Next Header field. - Const files re-rendered offline through each crawler's own template with member data untouched; Method.get and OptionType.register docstrings follow. - registry-protocol.rst and EnumLookup._validate_value say every registry overrides the hook; line citations the change shifts are re-pointed. - A new test walks every registry at runtime and fails on main, and pins the bounds no FLAG gives; the no-mint sweep now mints inside each range. Closes #1816
JarryShaw
force-pushed
the
fix/1816-register-validates-every-registry
branch
from
October 16, 2026 14:34
020f2a9 to
5ca7d2d
Compare
Owner
Author
|
Verdict: GOOD TO GO at
The loud fallback for explicit out-of-range calls with a default is noted in the PR body. |
This was referenced Oct 16, 2026
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.
Please follow the guide below
You will be asked some questions, please read them carefully and answer honestly
Put an
xinto all the boxes [ ] relevant to your pull request (like that [x])Use Preview tab to see how your pull request will actually look like
Searched for similar pull requests
Followed the coding style (
make pylint,make mypy,make isort)make testpasses, and a test case covers the change. Narrow runs only, listed below.Added a changelog entry under
docs/source/changelog/and regeneratedCHANGELOG.md, if the change is user-visible: N/A — 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?
Tick the commit type your subject line carries.
fix— corrects a defectfeat— adds a featureperf— changes performance, not behaviourrefactor— changes neither behaviour nor performancetest— tests onlydocs— documentation onlyci— workflows or build toolingrelease— bumps the version or rolls up a distributionchore— anything elseDescription
Closes #1816, and widens the scope to every enum per your note on #1818. Before this PR,
EnumRegistry.registercalled the_validate_valuehook, but onlyAppTypeoverrode it. SoHardware.register(70000, 'x')would mint a member thatHardware.get(70000)then returned._validate_valueoverride. It runs the same check the template already writes into_missing_and raisesEnumValueErrorwith the same message.FLAG, or the template's own range: 0-999 for StatusCode/ReturnCode, 0-9 for ResponseKind/GroupingInformation,strfor the string-valued ones._missing_, so they get a type check and the 8-bit Next Header range (RFC 8200).mainshows that only the override, its imports and two docstrings changed, with no member data touched.registerraises if and only ifgetrejects, that the hook agrees with_missing_on boundary values, and that no registered value is refused. It fails onmain. The no-mint sweep now mints inside each registry's range.Behaviour note:
get(out_of_range, default)still returnsdefault, but now also logs one CRITICALEnumValueErrorand installs pcapkit's excepthooks; onmainit was silent. The cause is that the hook raises a loudEnumValueErrorbeforegetfalls back todefault, as #1818 already does forAppType. Measured: no parse path triggers it. Over the sample captures there are 0 hook rejections, and none of the library's registry.get()call sites passes a default or a value wider than its hook allows. Aquiet=Trueerror on thegetpath would remove the noise, as a follow-up if wanted.Left alone:
getrejects butregistermay mint, such asCauseCode(0). These are documented inregistry-protocol.rst.Command.getdefect, filed separately.Narrow runs, all passing:
tests/const: 341 passed.tests/vendor: 142 passed.tests/corekit: 620 passed, 16 skipped.tests/project: 949 passed, 1 skipped.