Skip to content

refactor(corekit,utilities): detect get_annotations, UnionType and dict reversal by version, not by probe (#1709) - #1730

Merged
JarryShaw merged 1 commit into
mainfrom
refactor/1709-compat-version-gates
Oct 14, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
refactor/1709-compat-version-gates

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

Please follow the guide below

What is the purpose of your pull request?

Tick the commit type your subject line carries.

  • fix — corrects a defect
  • feat — adds a feature
  • perf — changes performance, not behaviour
  • refactor — changes neither behaviour nor performance
  • test — tests only
  • docs — documentation only
  • ci — workflows or build tooling
  • release — bumps the version or rolls up a distribution
  • chore — anything else

Description of your pull request and other information

Closes #1709. This applies the owner's rulings on #1701 and #1703 to the six stdlib feature probes left in pcapkit/.

  • compat re-exports: get_annotations (3.10+, otherwise a class's own __dict__['__annotations__']) and UnionType (3.10+, otherwise None), both behind sys.version_info. infoclass and protocol import both from there, and _own_annotations is gone.
  • MultiInfo / OrderedMultiInfo: they bind __reversed__ behind sys.version_info >= (3, 8) instead of hasattr(dict, '__reversed__').
  • _make_index_calls: it reads an ast call's end_lineno behind sys.version_info >= (3, 8) instead of through getattr.
  • New guard: tests/project/test_stdlib_feature_probes_1709_unit.py scans pcapkit/ for literal-name getattr/hasattr calls on a module or builtin class, or for end_lineno/end_col_offset on any object. It fails on main and on round 1 of this PR.
  • The other 224 literal-name calls read optional protocol fields, pcapkit's own attributes, third-party objects, or stdlib attributes every supported Python has.
  • Behaviour: unchanged. Dumps of 492 Info classes are byte-identical before and after on 3.8, 3.9, 3.10 and 3.14.
  • Conflict with refactor(corekit)!: move chardet into corekit (#1712) #1729: both edit protocol.py's import lines. Whichever merges second gets rebased.

Tests: the compat, infoclass, probe-scan, round-trip and protocol-make selections pass on 3.8, 3.9, 3.10 and 3.14.

…ct reversal by version, not by probe (#1709)

- compat re-exports get_annotations behind a sys.version_info gate:
  inspect.get_annotations from 3.10, and below it the reader infoclass
  had, a class's own __dict__['__annotations__'], uncopied
- compat re-exports UnionType: types.UnionType from 3.10, None below it
- infoclass and protocol take both from compat in place of their
  getattr(inspect/types, ...) probes; _own_annotations is gone
- MultiInfo and OrderedMultiInfo bind __reversed__ behind
  sys.version_info >= (3, 8) instead of hasattr(dict, '__reversed__')
- _make_index_calls reads an ast call's end_lineno behind
  sys.version_info >= (3, 8) instead of getattr(node, 'end_lineno', ...)
- a project test scans pcapkit/ for getattr/hasattr by literal name of
  a module or builtin class, or of end_lineno/end_col_offset on any
  object; on main it reports exactly these six

Tests: test_compat, test_infoclass, the probe scan, from_dict,
MultiInfo, protocol payload and make() selections pass on 3.8, 3.9,
3.10 and 3.14; 492 Info signatures and nested types byte-identical to main.

Closes #1709
@JarryShaw JarryShaw added refactor Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix) review: good-to-go Cross-review at the current head says ready; CI state is separate labels Oct 14, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Verdict: GOOD TO GO at cfb909b52. Sonnet cross-reviews (Opus wrote the change) checked two rounds.

  • Round 1 missed one probe: getattr(node, 'end_lineno', node.lineno) at protocol.py:97. Round 2 gates it, and the widened scan catches the old line.
  • Gates: they select exactly the old behaviour on 3.8, 3.9, 3.10 and 3.14. Old and new readers agree on 7 class shapes, and the 492-class dumps are byte-identical.
  • compat.__all__: each name appears once. The line-number comment in test_compat.py still matches the file.
  • Enumeration: I independently listed every literal-name getattr/hasattr call. None is a stdlib version probe.

@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 89.35% (unit tier, Python 3.15, cfb909b52, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 3 20 3 95.16%
pcapkit/const 18860 954 2368 868 91.06%
pcapkit/corekit 2374 67 762 35 96.49%
pcapkit/dumpkit 275 3 100 3 98.40%
pcapkit/foundation 2885 144 1010 34 94.20%
pcapkit/interface 138 7 52 5 93.68%
pcapkit/protocols 17170 225 4586 189 98.08%
pcapkit/toolkit 1148 290 450 10 71.21%
pcapkit/utilities 515 4 158 4 98.81%
pcapkit/vendor 4417 2342 1010 157 43.38%

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

@JarryShaw
JarryShaw merged commit 4754751 into main Oct 14, 2026
54 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 14, 2026
@JarryShaw
JarryShaw deleted the refactor/1709-compat-version-gates branch October 14, 2026 16:41
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

refactor(corekit): take the stdlib version detections (get_annotations, UnionType, dict reversal) from compat behind version gates

1 participant