Skip to content

refactor(utilities): move the ContextVars shared across modules into pcapkit.utilities.contextvars - #2623

Merged
JarryShaw merged 1 commit into
mainfrom
refactor/2616-contextvars
Nov 2, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
refactor/2616-contextvars

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • refactor — changes neither behaviour nor performance

Description of your pull request and other information

The ContextVars that more than one module reads now live in a new leaf module, pcapkit.utilities.contextvars. They are beholding, frame_depth, in_fragment and rebuilding, under public names in __all__, with no re-export at their old paths. The module-private ones stay with their owners. This is the owner's option 2 on #2616. The names were underscore-private and absent from every __all__, so nothing public breaks.

tests/project/test_shared_contextvars_2616_unit.py fails when a module takes a ContextVar from anywhere else: top-level, function-local, TYPE_CHECKING, relative or attribute imports, or a re-export by import. It also fails when the shared module holds a variable with fewer than two readers. utilities-or-corekit.rst records where a ContextVar lives. Both import-boundary tests pass.

A Sonnet cross-review returned GOOD TO GO. It ran 20 guard mutations and checked every set/reset pair. Semantics are unchanged.

Closes #2616

…xtvars (#2616)

- pcapkit/utilities/contextvars.py: a leaf module holding beholding,
  frame_depth, in_fragment and rebuilding, public and in __all__. It imports
  nothing from pcapkit.
- Their private definitions leave corekit.checksum.internet,
  corekit.decorators and protocols.protocol with no re-export; every reader
  imports them from utilities.contextvars. Module-private ContextVars stay put.
- tests/project/test_shared_contextvars_2616_unit.py fails on a ContextVar
  taken across modules from anywhere else, and on a shared one that is
  private, missing from __all__ or read by one module alone.
- Docs: an API page in the utilities toctree, and a Context Variables section
  on utilities-or-corekit.rst.
@JarryShaw JarryShaw added this to the PyPCAPKit v1.6 milestone Nov 2, 2026
@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 Nov 2, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at 541cc02dc, from a Sonnet cross-review:

  • The four shared ContextVars keep their defaults, and every set/reset pair still matches.
  • No old private name remains anywhere in pcapkit/, including code merged after the base.
  • The guard caught all 20 of the mutations run against it.
  • Both import-boundary tests pass.
  • It merges cleanly onto main, and the merged tree passes.

@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 2, 2026
@JarryShaw
JarryShaw merged commit f656fab into main Nov 2, 2026
61 of 62 checks passed
@JarryShaw
JarryShaw deleted the refactor/2616-contextvars branch November 2, 2026 04:31
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Nov 2, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Nov 2, 2026
JarryShaw added a commit that referenced this pull request Nov 2, 2026
… kinds into 1.6.0 (#2449)

- Added: pad_length and PaddingField's align/after form (#2624), and
  pcapkit.utilities.contextvars (#2623); the old private names get no
  entry, as for the other private API.
- Changed: the weekly Issue and PR Kinds workflow, beside the milestone
  workflow's entry (#2626).
- The conventions entry records where a context variable lives (#2623),
  and the role-kind citation rule with its test (#2626).
- No entry for #2626's heading and Mermaid fixes, #2564 or fa9af52.
- CHANGELOG.md regenerated; util/changelog_md.py --check passes.
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(utilities): a home for the ContextVars shared across the library

1 participant