Skip to content

fix(pcap): Frame.from_data cannot be called — it has no way to pass num and header - #1147

Merged
JarryShaw merged 1 commit into
mainfrom
fix/1126-frame-from-data
Oct 6, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/1126-frame-from-data

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner
  • Searched for similar pull requests
  • Followed the coding style (make pylint, make mypy, make isort) — run with the Makefile flags on the two changed source files; no new findings vs main
  • make test passes, and a test case covers the change — the modules listed below only, not the full suite
  • Added a changelog entry under docs/source/changelog/ and regenerated CHANGELOG.md, if the change is user-visible — N/A, added centrally after the wave

What is the purpose of your pull request?

  • fix — corrects a defect

Description of your pull request and other information

Closes #1126. ProtocolBase.from_data(data, **kwargs) now forwards extra keywords to the construction, overriding _make_data's. Caller keywords get the strict construction-keyword check, so a typo raises UnsupportedCall. PCAPNG.from_data had the same defect (it needs num/sct/ctx), and this fixes it too.

Before: Frame.from_data(info, num=1, header=hdr) raised TypeError: from_data() got an unexpected keyword argument 'num'. PCAPNG.from_data(shb.info, num=0, sct=1, ctx=None) failed the same way.
After: all 6 frames of in.pcap round-trip byte for byte, and so does the test.pcapng SHB (164 B).

Also: dropped the stale ts_src/prio examples from the _check_construction_keywords comment (both fixed in #1115). Removed the _make_data patch from test_make_data_keys_unit.

Tests: new tests/protocols/misc/pcap/test_frame_from_data_runtime.py. Without the fix it gives 8 failed, 1 passed; with the fix it gives 3 passed, 6 subtests passed. Passing modules: test_make_data_keys_unit (2), test_construction_keyword_check_unit (22), test_protocol_base_unit (15), pcap/test_header_frame_unit (6), pcap/test_frame_runtime (4), misc/test_pcapng_unit (97), and tests/project (385 passed, 1 skipped).

…um and header

ProtocolBase.from_data now takes **kwargs and forwards them to the
construction, overriding what _make_data returns, so Frame can be
rebuilt with from_data(info, num=..., header=...) and PCAPNG with
num/sct/ctx. Caller keywords get the strict construction-keyword check.

Drops the stale ts_src/prio examples from the _check_construction_keywords
comment (both fixed in #1115), and the _make_data patch in
test_make_data_keys_unit.

Closes #1126
@JarryShaw JarryShaw added fix Pull requests that fix a defect (fix: subject prefix) review: running A cross-review is in flight against the current head - no verdict yet labels Oct 6, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Cross-review verdict on f39c145d2: GOOD TO GO (ran on Sonnet; author Opus)

  • The fix: on main, Frame.from_data(info, num=…, header=…) raises unexpected keyword argument 'num'. On this PR, all 6 in.pcap frames round-trip byte for byte, and so does the test.pcapng SHB (164 B) through PCAPNG.from_data(…, num=, sct=, ctx=).
  • Tests: with protocol.py reverted, the new module fails 8 tests. test_make_data_keys_unit, test_construction_keyword_check_unit and test_frame_runtime pass.
  • No subclass overrides from_data. The only internal caller passes no keywords, so existing calls are unaffected.
  • Strict check: caller keywords go through the same _check_construction_keywords that __init__ uses. A typo raises UnsupportedCall, while keywords produced by _make_data still only warn.
  • Not breaking: this is an additive signature change, so fix alone is the right label.

Nit: the explicit _layer/_protocol/__context__ filter is redundant with OUT_OF_BAND_KEYWORDS. The ext.rst:~266 and _check_construction_keywords docstrings are now half out of date; those are noted for #1103.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Coverage: 88.75% (unit tier, Python 3.14, f39c145d2, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 4 93.55%
pcapkit/const 18757 1035 2342 846 90.23%
pcapkit/corekit 1873 91 578 22 94.33%
pcapkit/dumpkit 136 0 40 0 100.00%
pcapkit/foundation 2425 145 842 34 92.56%
pcapkit/interface 112 7 40 5 92.11%
pcapkit/protocols 15660 188 3944 163 98.18%
pcapkit/toolkit 487 65 144 1 85.42%
pcapkit/utilities 429 4 122 4 98.55%
pcapkit/vendor 4409 2359 1006 158 42.84%

Per-file detail: the coverage-html artifact of this run.

@JarryShaw
JarryShaw merged commit 73ae662 into main Oct 6, 2026
41 checks passed
@JarryShaw
JarryShaw deleted the fix/1126-frame-from-data branch October 6, 2026 22:37
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(pcap): Frame.from_data cannot be called — it has no way to pass num and header

1 participant