refactor(vendor): finish the %-to-f-string sweep on the four bespoke templates - #803
Conversation
…templates GitHub issue #798 (the remainder #792 deliberately left out). Three parts: - The three other `_missing_` guards still raising with `%` -- `pcapkit.vendor.tcp.flags`, `pcapkit.vendor.ftp.command` (all three of its guards: FEATCode, CommandType, Command), `pcapkit.vendor.http.method` -- converted to f-strings, matching #792's form for the fourth. - AppType's three `%`-formatted dunders (`__new__`, `__repr__`, `__str__`) and the `get()` mint-fallback's `extend_enum(..., 'PORT_%d_%s' % ...)`, plus the 766-line span-handling tail's `extend_enum(..., '<name>_%d' % value, ...)` calls, all converted. `__new__`'s format sets every real member's underlying `StrEnum` value, so this is proven byte-identical member by member (12,391 members: TCP 6147, UDP 6143, SCTP 91, DCCP 10), not spot-checked. - The module-level `consider-using-f-string` disable dropped from `tcp.flags` and `reg.apptype.apptype`, which carry no more `%`-formatted code. Left in place on `ftp.command` and `http.method`: both still render a `__repr__` using `%`, out of this issue's stated scope. Edited in the vendor templates (braces doubled, since `BASE`/`LINE` are f-strings emitting f-strings) and applied by hand to the generated const files, not by a crawl -- `AppType.LINK` fetches IANA's live CSV. `BASE(...)` rendered with the committed file's own TABLE/MISS reproduces `pcapkit/const/reg/apptype/apptype.py` with 0 diff lines. `tests/const/test_const_enum_builtin_parity.py`'s `BESPOKE_TEMPLATES` dict updated to the new f-string guard text for all four modules, plus two new tests checking the old `%` form is gone from each committed const module (no `requests` gate needed) and that the disable drops only where nothing else needs it. A new member-sweep test in `test_const_apptype_split_unit.py` pins the dunder byte-identity. Build/test: `tests/const`, `tests/vendor`, `tests/test_tier_guard.py`, `tests/project` all green (356 tests / 40,096 subtests). Coverage of the touched modules 52.15% -> 52.21%. pylint 9.47 -> 9.48/10 on the eight touched files (R0801 17 -> 16). mypy: 2 findings, both pre-existing on `main` and on lines this diff does not touch. isort clean at `-l100 -ppcapkit`. Closes #798
|
Cross-review verdict: GOOD TO GO (opus; author was sonnet). Both decisive claims reproduced independently, each with sensitivity controls — which is what makes the zeros mean something. 1. Four controls, because extraction-based equality can be circular: base The probe cannot see inside TABLE/MISS, so those were checked separately: TABLE byte-identical base↔head; MISS 2,298 lines both sides, 766 differing, all 766 matching the mechanical 2. Byte-identity over 12,391 members — confirmed, TCP 6147 / UDP 6143 / SCTP 91 / DCCP 10, 3. Brace doubling — confirmed by rendering all four templates against their committed files, every one byte-identical, plus runtime proof no brace is doubled where it shouldn't be ( One claim refuted, and it is a description error rather than a defect. The body says pylint Everything else confirmed: three Unverified, and I am accepting that rather than holding the PR: the coverage figures (52.15% → 52.21%) and mypy were not run. Per the new review time budget, an unfinished check is reported rather than chased — CI is green on all 27 checks, and neither number is load-bearing for correctness. Flipping to |
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
Closes #798, the remainder #792 deliberately left out. Converts the three other bespoke
_missing_guards (tcp.flags,ftp.command's three,http.method) to f-strings, convertsAppType's three%-formatted dunders plus itsget()mint fallback and the 766-line span-handling tail, and drops the module-levelconsider-using-f-stringdisable fromtcp.flagsandreg.apptype.apptype(kept onftp.command/http.method, whose__repr__still uses%, out of scope here).Edited by hand in the vendor templates and their generated
pcapkit/constcounterparts — not by a crawl, sinceAppType.LINKfetches IANA's live CSV.__new__'s format sets every real member'sStrEnumvalue, so it is proven byte-identical member by member across all 12,391 members, not spot-checked.Tests:
tests/const,tests/vendor,tests/test_tier_guard.py,tests/projectall green (356 tests / 40,096 subtests). Coverage of the touched modules 52.15% → 52.21%. pylint 9.47 → 9.48/10. mypy: 2 pre-existing findings, unrelated to this diff.