refactor(const): convert AppType's six %-style raises to f-strings (#792) - #797
Conversation
|
7 FAILED legs — Python 3.10/3.11/3.12/3.13/3.14 and Engines 3.12/3.13 — and they are all one defect. Root cause, from the 3.10 job log:
The guard was not removed; the test pins its formatting rather than its presence. But it is not simply over-specified, because of this: The test loops over four templates with one expected string. This PR converted one of them, so that string can no longer serve all four — it now fails for So there is a scope decision, and I am taking the narrow one:
The remaining three templates' Worth noting the worker's pre-flight check was not wrong, just aimed one target over: it reported "found no test pinning any of the three dunders' exact format", which was true. A test pinning one of the six raises it converted is what it missed. |
053c088 to
ecfb1cd
Compare
|
Revised to So a genuinely deleted guard still fails, on the right subTest, with #647 named. That was the risk in relaxing a shared literal and it is closed.
The It also confirmed Unchanged and re-derived: the template-equivalence diff still shows exactly 2 non-equal regions (the
CI is re-running on the new head — 5✅ / 3⏭ / 0❌ with 21 in flight as I write. The cross-review on this PR died on a rate limit ( |
|
Cross-review at The test's comment cites the wrong issue. It says "#796 tracks sweeping them" — but #796 is And it caught that What it verified independently, all five starred claims:
One pre-existing test weakness it surfaced by mutation, not introduced here: moving the guard text into a dead comment ( It marked the "pylint |
) The generated `pcapkit.const.reg.apptype.apptype` module had 6 `raise ValueError(...)` calls still using `%` formatting, left that way by #783 so its own diff over a 12,391-member file stayed reviewable. Per the maintainer's f-string convention (#783), they now match the other 605 f-string raises tree-wide: - `TransportProtocol._missing_`: `'%r is not a valid %s' % (...)` -> `f'{value!r} is not a valid {cls.__name__}'` - `AppType.__new__`: the "holds no members" guard - `AppType._dispatch`: the non-port `key` guard and the trailing "names no transport protocol registry" guard - `AppType._missing_`: both range/registry guards (same message as the first bullet) Each message was verified byte-identical old vs new (same repr()/str() semantics for %r/!r and %s/{}), and exercised through its real call path (`AppType.get('http', proto=tcp)`, `AppType.get(80, proto=undefined)`, `extend_enum(AppType, ...)`, out-of-range `AppType(...)`) with matching live exception text before and after. The edit is in the `BASE` template of `pcapkit/vendor/reg/apptype/apptype.py` (braces doubled, as an f-string template emitting f-strings) and applied by hand to the const file rather than by a crawl, to avoid rewriting the IANA-derived member rows. Expanding `BASE` with dummy TABLE/MISS and diffing against the const file shows exactly 2 non-equal regions -- the docstring's list-table and the range-row tail of `_missing_`, both TABLE/MISS-dependent -- and 0 elsewhere. Left unconverted, and said why in the PR: the three %-formatted dunders (`__new__`, `__repr__`, `__str__`) the issue also mentions -- out of the issue's stated raise-only scope, and `__new__`'s format string sets every member's underlying `StrEnum` value across all ~12,391 real members, a much larger blast radius than an error path. The module-level `consider-using-f-string` pylint disable stays: those dunders and the `extend_enum(..., '%d' % value, ...)` calls still use `%`. `tests/const/test_const_enum_builtin_parity.py::test_every_bespoke_template_ carries_the_guard` (GitHub issue #647) pinned all four bespoke vendor templates' guards against one shared `%`-style literal, so converting `reg.apptype.apptype`'s copy broke it in CI (7 legs). `BESPOKE_TEMPLATES` is now a dict keyed to each template's own guard text -- the other three still raise with `%` (#798 tracks sweeping them, the `%`-formatted dunders, and dropping the disable) -- rather than an `or` of both forms, which would let a genuinely deleted guard pass. Proved by deleting the guard from `pcapkit.vendor.tcp.flags` locally: the test failed with the expected subTest and message, then the file was restored and the tree verified clean. Build/test: `tests/const/test_const_apptype_split_unit.py` (19), `tests/vendor/test_vendor_reg_apptype_generator_unit.py` (6), and `tests/const/test_const_enum_builtin_parity.py` (20, `requests` importable so neither guard test skips) all pass under both pytest and plain unittest. mypy clean before and after. pylint: 0 new findings in either touched apptype file; R0801 unchanged at 575 tree-wide. Closes #792
ecfb1cd to
ae6d22f
Compare
|
Revised to The comment now reads "#798 tracks sweeping them, along with the To be clear about whose error this was: I put
CI is re-running on the new head: 16✅ / 3⏭ / 0❌ with 11 in flight. Setting Unpublished and unmerged — yours to take. |
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 changeAdded a changelog entry under
docs/source/changelog/and regeneratedCHANGELOG.md, if the change is user-visibleWhat 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 toolingchore— anything elseDescription of your pull request and other information
Converts the six remaining
%-style raises in the generatedAppTypeconst module to f-strings (#783's ruling). Each message was provenold == newbyte-identical, and re-derived through its real call path (AppType.get('http', proto=tcp),AppType.get(80, proto=undefined),extend_enum(AppType, ...), out-of-rangeAppType(...)) with matching live exception text before/after.The edit is in the
BASEtemplate ofpcapkit/vendor/reg/apptype/apptype.py(doubled braces) and applied by hand to the const file to avoid an IANA crawl rewriting member rows. RenderingBASE(...)and diffing against the const file gives exactly 2 non-equal regions — theTABLE/MISS-dependent docstring table and_missing_range tail — and 0 lines differing elsewhere.Left unconverted: the three
%-formatted dunders (__new__/__repr__/__str__) — out of the issue's raise-only scope, and__new__'s format sets every one of ~12,391 real members'StrEnumvalue, a far bigger blast radius than an error path. Theconsider-using-f-stringdisable stays earned by those and byextend_enum's'%d'calls.19+6 tests pass under
pytestandunittestalike; mypy clean before/after; pylint 0 new findings,R0801unchanged at 575.Closes #792