Repository navigation
fix(const): reject an out-of-range port in AppType.register (#1792) - #1818
Conversation
AppType.register neither called nor overrode _validate_value, so TCP.register(70000, 'x') minted a member that AppType.get(70000, proto='tcp') then returned, although get raises ValueError for a port outside 0-65535. - AppType overrides _validate_value with the check _missing_ makes and raises EnumValueError, as the registry-protocol convention asks of an override, with the message get raises, so register and get refuse the same ports in the same words. register calls it after its duplicate check, as EnumRegistry.register does. Template and generated module changed identically, including the EnumValueError import. - EnumLookup._validate_value's docstring no longer says AppType skips it. - Re-point the line citations the change shifts. - tests/const/test_const_apptype_register_range_1792_unit.py covers TCP, UDP, SCTP and DCCP; it fails on main. Closes #1792
|
Verdict: GOOD TO GO at |
|
Coverage: 89.60% (unit tier, Python 3.15,
Per-file detail: the |
|
Is this check needed for all other enums as well? I dont think |
|
Yes, every other registry has the same gap, and you're right that I measured this just now on This PR fixes
My recommendation is to merge this one as it stands and then do #1816. If you'd rather have it all in one PR, I can widen this one instead. |
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 elseSummary
TCP.register(70000, 'x')minted a member, and so did-1, after whichAppType.get(70000, proto=tcp)returned it, althoughgetrejects an out-of-range port (#758).EnumRegistry.registervalidates through the_validate_valuehook, butAppTypeneither overrode it nor called it.AppType._validate_valuerejects anything that is not anintin 0–65535, the check_missing_makes.registercalls it, in the same order asEnumRegistry.register. The change is identical in the vendor template and the generatedpcapkit/const/reg/apptype/apptype.py.registry-protocol.rst, the hook raisesEnumValueError, which derivesValueError, with the same messagegetuses for an out-of-range port. Owner note: as a pcapkitBaseErrorit is loud (CRITICAL log, excepthooks outside devmode), likeEnumLookup.get's miss. The registry's otherregisterrefusals are still builtinValueError.tests/const/test_const_apptype_register_range_1792_unit.pyfails onmainacross TCP, UDP, SCTP and DCCP. A mutant raising builtinValueErrorfails it too.tests/const,tests/vendor,tests/corekitandtests/projectpass.versionchanged:AppTypehad noregisterin 1.4.1.post2. The same gap in the other registries is fix(corekit): registries' register accepts values their get rejects #1816.Closes #1792