Skip to content

refactor: remove unreachable branches, commented-out raises and unused test helpers #2318

Closed

Description

@JarryShaw

Is your feature request related to a problem? Please describe.
These branches and names can never run or be read:

  • Header.read (pcap): the if _decl is None: raise FileError(...) branch is dead, because the schema's magic_number_callback raises first. Header(io.BytesIO(b'\x00\x01\x02\x03' + bytes(20))) raises ProtocolError: invalid magic number, so the Raises: FileError in the docstring is wrong too.
  • _read_opt_qs in IPv4, HOPOPT and IPv6_Opts: the final else: raise ProtocolError(... unknown QS function ...) is dead. Since fix(ipv4): an unassigned Quick-Start function code fails the whole header #1322 and fix(ipv6-opts): an unassigned Quick-Start function code fails the whole header #1237 the schema sends an unassigned function to UnassignedOption; I parsed every function nibble from 0 to 15 and none reached it.
  • _read_opt_calipso (HOPOPT, IPv6_Opts): both length guards are dead, because calipso_pad_len already raises FieldValueError: HOPOPT: invalid CALIPSO option length: 7 for any len < 8 + cmpt_len * 4. The % 8 != 0 clause is redundant even by itself.
  • Commented-out raise lines sit next to the warn that replaced them: _make_opt_pad (HOPOPT, IPv6_Opts, MH), IPv4._read_opt_sec, HIP._read_param_hip_cipher, the HIP schema's pre_unpack, HTTP/2._read_http_none, PCAP-NG's ts_* properties and _get_* helpers, and the PCAP-NG schema's block-length post_process.
  • _read_opt_qs (HOPOPT, IPv6_Opts) repeats # pylint: disable=unused-argument on its def line.
  • examples/generators/dispatch.py: code_name never reads _internet_enum, because no key in Internet.__proto__ is a bare int any more. The code_name docstring still says one is.
  • tests/project/test_release_tags_the_run_sha_1634.py: the '--json assets --jq .assets[].name' arm of FAKE_GH answers a query nothing makes; util/release_upload.py only sends ASSETS_JQ.
  • tests/project/test_sweeps_on_latest_only_1732.py: GATING is defined and never read, and test_pypy_worker_memory_2005 does not import it either.
    Describe the solution you'd like
    Delete each one, change Header.read's Raises: to ProtocolError, and update the comments and docstrings that describe what was removed (code_name, the FAKE_GH note).
    Describe alternatives you've considered
    Having magic_number_callback raise FileError, so that the documented exception becomes true. That changes the exception that every caller now gets for a bad file.
    Additional context
    Dead branches make the code look as if it handles cases it never sees, and coverage cannot reach them.

Related: #2300 rewords the magic-number message that Header.read actually raises; #2312 was split out of this list because it needs a ruling.

Activity

  1. added this to the PyPCAPKit v1.5 milestone on Oct 26, 2026
  2. added
    testPull requests that add or correct tests (test: subject prefix)
    refactorRestructuring for its own sake — neither a fix nor a new capability (refactor: prefix)
    on Oct 26, 2026
  3. moved this to Pending in PyPCAPKiton Oct 26, 2026
  4. JarryShaw commented on Oct 26, 2026

    @JarryShaw
    OwnerAuthor

    Blocked until the round-7 fix PRs for #2268–#2316 merge. This change spans the protocol modules those fixes edit, so it starts from the merged tree.

  5. added
    blockedDeferred pending another issue or decision; see the last comment for what unblocks it
    on Oct 26, 2026
  6. moved this from Pending to Blocked in PyPCAPKiton Oct 26, 2026
  7. JarryShaw commented on Oct 27, 2026

    @JarryShaw
    OwnerAuthor

    Fixing #2318 turned up a judgment call. Three existing tests reached what the issue calls dead code, but only by hand-fabricating a schema object and calling the private reader directly — bypassing unpack() entirely, which no real parse can do:

    • a Header with a bad magic number, built via object.__new__ instead of a real byte stream, to reach a FileError branch;
    • two IPv4/IPv6 cases with a QuickStartRequestOption/CALIPSOOption schema hand-built to disagree with itself.

    My recommendation: these are genuinely dead on any real input, so the branches come out and the three tests move to the real path (e.g. Header(io.BytesIO(bad_bytes))), which the PR already does. If you'd rather keep a guard reachable only by a fabricated object — for defence-in-depth against a hand-built schema passed in some other way — say so and I'll restore it with a test that builds it that way instead.

  8. added
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    wipWork in flight - a covering PR is open or an agent is actively on it
    and removed
    blockedDeferred pending another issue or decision; see the last comment for what unblocks it
    on Oct 27, 2026
  9. moved this from Blocked to Needs decision in PyPCAPKiton Oct 27, 2026
  10. JarryShaw commented on Oct 27, 2026

    @JarryShaw
    OwnerAuthor

    take your recommendations

  11. JarryShaw commented on Oct 27, 2026

    @JarryShaw
    OwnerAuthor

    Ruling noted: taking the recommendation (remove the branches, move the three tests to the real path). Already implemented that way in the committed fix; proceeding to PR.

  12. removed
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Oct 27, 2026
  13. moved this from Needs decision to WIP in PyPCAPKiton Oct 27, 2026
  14. JarryShaw commented on Oct 27, 2026

    @JarryShaw
    OwnerAuthor

    Closing note for the record: this issue's original "dead code" claim for _read_opt_qs's unknown-QS-function arm was based on parse-only evidence (reachable only by calling the private reader directly). The fix in #2378 found that arm is actually reachable via the public construction path too — a QuickStartRequestOption/QuickStartReportOption built directly with an unassigned func hits it regardless of parse dispatch — so it was kept rather than removed, unlike the other two guards this issue named (Header.read's FileError, _read_opt_calipso's length guards), which are confirmed genuinely dead through both construction and parse routes.

  15. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorRestructuring for its own sake — neither a fix nor a new capability (refactor: prefix)testPull requests that add or correct tests (test: subject prefix)

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions