Skip to content

refactor(protocols): align ProtocolBase.__registry__ handling and entry layout with the other registry maps #2773

Closed

Description

@JarryShaw

What
Owner questions after #2770: does ProtocolBase.__registry__ follow the handling the other registry maps use (lock, read-only copy, register_protocol checks)? And should its built-in entries be grouped by layer? Audit at 3c4b30e2b, read-only, with key claims re-checked by me:

  • Matches the other maps:
    • _shipped_registry is a MappingProxyType(dict(...)) snapshot, built the same way as the Extraction/TraceFlow _shipped_* maps, and used for the same restore.
    • register_protocol raises the same RegistryError type checks as register, the wrapper also validates (as registry-protocol.rst has both sides do), and both return None.
    • The clash warning is a RegistryWarning in the same shape.
    • The docs (#:, Warns:, the # NOTE: tag) match.
  • Differs:
    1. Lock: _registry_lock is the first lock on any registry map. It serialises only get_protocol's first resolution (refactor(protocols)!: replace the pcapkit.protocols.__proto__ dict with an auto-registering Registry class #2763, an import deadlock). register_protocol, the __init_subclass__ setdefault and _release_name all write without it, as every other map does.
    2. Restore path: _release_name (foundation.registry.protocols) writes lease.displaced straight into the map instead of going through register_protocol.
    3. Descriptors: register_protocol takes a class only, where register/register_option also take a ModuleDescriptor. This follows from registering a class by its own name.
    4. Keys: keys are upper-case, inherited from the old __proto__ dict, while the other string-keyed maps use lower-case.
  • Layer grouping: no registry dict in the tree uses layer comments; only protocols/__init__.py's __all__ does. protocol-member-order.rst orders maps "alphabetically by key where there is no enum". The guard does not check __registry__ (it skips string-keyed dunder maps).

Activity

  1. added
    refactorRestructuring for its own sake — neither a fix nor a new capability (refactor: prefix)
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Nov 4, 2026
  2. JarryShaw commented on Nov 4, 2026

    @JarryShaw
    OwnerAuthor

    Decision needed.

    1. Lock scope:

      Rec: (c) once fix(utilities): concurrent first access to lazy protocol exports deadlocks the import system #2771 lands, otherwise (a). A single lock in the shared lazy-import helper is the established place, and no other map locks.

    2. Restore path:

      • (a) Keep _release_name's direct write, which restores exactly what was displaced.
      • (b) Route it through register_protocol.

      Rec: (a), with a one-line comment saying why.

    3. Grouping by layer:

      • (A) Keep sorting by key: it follows the page, and each entry's module path already shows its layer.
      • (B) Group by layer (# Link Layer, …, # Miscellaneous for Frame/Header/IP_Pseudo/NoPayload), alphabetical within each group, and amend the page in one sentence.
      • (C) Group without any order rule.

      Rec: (A). If you prefer (B), it is a comment-only edit plus the page amendment. (C) would drift unguarded.

    4. Guard gap: the member-order guard doesn't check string-keyed maps, so "alphabetically by key" is unenforced. Rec: extend the guard as part of whichever option you choose for 3.

  3. added this to the PyPCAPKit v1.6 milestone on Nov 4, 2026
  4. moved this to Needs decision in PyPCAPKiton Nov 4, 2026
  5. JarryShaw commented on Nov 4, 2026

    @JarryShaw
    OwnerAuthor
    1. take (c); and i dont think we used this in other registry mappings. so maybe over engineering.
    2. take the path other registry mappings taken. it's not necessary to preserve. also maybe over engineering.
    3. take (B)
    4. yes
  6. JarryShaw commented on Nov 4, 2026

    @JarryShaw
    OwnerAuthor

    Reconciled. Every answer is now settled.

    1. (c): the registry lock goes. No other registry map uses one, and fix(utilities): concurrent first access to lazy protocol exports deadlocks the import system #2771's fix covers the import deadlock it guarded against. _registry_lock and its use in get_protocol are removed in fix(utilities): concurrent first access to lazy protocol exports deadlocks the import system #2771's PR, once its shared lazy_exports lock is in place.
    2. Restore follows the other maps. _release_name restores through the same path the other registry maps' restores use, and there is no need to bring back exactly the displaced object. The special-casing goes.
    3. (B): entries grouped by layer. __registry__'s built-in entries get layer comments (# Link Layer, # Internet Layer, # Transport Layer, # Application Layer, # Miscellaneous), alphabetical within each group. protocol-member-order.rst gets a one-sentence amendment.
    4. Yes: the guard checks string-keyed maps. That covers the alphabetical rule, and for __registry__ it is applied group by group.

    Items 2–4 go in one PR together with #2772, because both edit protocol-member-order.rst and the member-order guard. Item 1 goes in #2771's PR. Each PR is marked "Part of #2773", and this issue closes when both have merged.

  7. added
    wipWork in flight - a covering PR is open or an agent is actively on it
    and removed
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Nov 4, 2026
  8. moved this from Needs decision to WIP in PyPCAPKiton Nov 4, 2026
  9. JarryShaw commented on Nov 4, 2026

    @JarryShaw
    OwnerAuthor

    Both parts have landed, so this is closed. #2779 covered items 2–4: the restore path, the layer grouping, and the guard for string-keyed maps. #2781 covered item 1, removing _registry_lock now that the shared import_lock guards first resolution.

  10. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Nov 4, 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)

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions