Repository navigation
fix(foundation): keep a user's verbose callback on every engine (#1874) - #1880
Conversation
- Uncomment the `_vfunc` annotation under its `#:` comment, so Sphinx attaches the description and the type the extraction page asks for. Typed `Callable[[Extractor, Any], Any]` rather than `VerboseHandler`, whose `Packet` union makes mypy reject the default and engine callbacks; mypy output on the extractor and the engines is unchanged. - Add a test that the comment attaches, read the way Sphinx's parser reads it, plus a cross-check against Sphinx itself where it is installed. Closes #1839
…1839) - Type `VerboseHandler` as `Callable[['Extractor', Packet], object]` and annotate `_vfunc` with it. The return is `object`, not `None`: every caller discards it, and `None` would make mypy reject a user callback that returns a value. - Narrow the frame to the engine's own packet type with `cast` inside the default callback and each engine's callback, so they accept the alias's `Packet` union. Runtime output is unchanged. - Pin the annotation and the alias's signature in the #1839 test. Refs #1839
- Replace `sys.stdout.write`, which takes one argument and so is no verbose callback at all, with `lambda e, f: sys.stdout.write(str(f))`: it takes the extractor and the frame and returns a value, so `object` accepts it where `None` would not. Refs #1839
|
Verdict: GOOD TO GO at
|
- Type `VerboseHandler`'s return as `Any` rather than `object`, per the owner's preference on #1867: every caller discards the result, and `Any` accepts any two-argument callback, whatever it returns. - Rewrite the NOTE above the alias to give that reason. - Pin `Any` in the signature test; the exact comparison still fails on a return of `None` or `object`. Refs #1839
- Extractor records in a private `_vfunc_default` flag whether `verbose=True` asked for the default printer; a callable leaves it unset. - The scapy, dpkt, pyshark, pypcap, pcap-ct and pypcapfile engines install their own printer only when that flag is set, so a caller's callback is no longer replaced. The `verbose=True` output is unchanged. - Note the fix in Extractor's 1.5.0 versionchanged block, and correct the `_flag_v` comment, which said it gated the per-frame call. - Test each installed engine end to end on in.pcap, with a recording callback and with `verbose=True`, and add fake-extractor cases for the engines that cannot run here. Closes #1874
…ack (#1874) - The custom-engine example in ext.rst tests `ext._vfunc_default`, not `ext._flag_v`, and says why: a `verbose=` callable must be kept. - Document `Extractor._vfunc_default` on the extraction page. - Run the verbose-callback module on every engine-tests leg, and update the tier guard test that pins the PyShark leg's TEST_PATHS line. Refs #1874
e24f384 to
657ef26
Compare
|
Verdict: GOOD TO GO at
Merge #1867 first. |
|
Not following, if there's a user provided callback, how will it be called then? My initial plan is to have user's callback replace the default printer and being called in the printer's place when version flag is set. |
|
That is what this PR does. The user's callback takes the printer's place, and nothing else changes. At
The bug in #1874 was that check. The engines tested |
|
Coverage: 90.05% (unit tier, Python 3.15,
Per-file detail: the |
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 elseStacked on #1867. It contains #1867's commits until that merges, so merge #1867 first. This PR's own commits are
9cbb10e4b(the fix) ande24f384fb(docs and CI)._vfunc_defaultflag whetherverbose=Trueasked for the default printer; a callable leaves it unset.their own printer only when that flag is set, so a caller's callback is
no longer replaced. The
verbose=Trueoutput is unchanged._flag_vcomment, which said it gated the per-frame call.callback and with
verbose=True, and add fake-extractor cases for theengines that cannot run here.
Closes #1874
Follow-up commit:
ext.rst's custom-engine example now testsext._vfunc_default,_vfunc_defaultis documented on the extraction page, and the new test module is added to every engine leg'sTEST_PATHS(an in-place, line-neutral edit). The PyPCAP and PyPCAPFile end-to-end cases first run in CI, because neither engine builds here.