Skip to content

refactor: replace direct dict subclasses and plain dict data fields with Info or Data #2726

Closed

Description

@JarryShaw

Ruling (owner, in session): do not subclass dict directly. Use Info, or a Data model, wherever one fits, and above all in pcapkit.protocols.data.

On main at 01f063467:

  • Direct dict subclasses: FrameRecord in foundation.traceflow.data, _Registries in const.reg.apptype, and MultiDict in corekit.multidict. MultiDict is itself a mapping implementation, so whether it is in scope needs a reason either way.
  • Plain dict in protocols.data: the PCAP-NG Decryption Secrets Block's entries is typed and built as a plain dict of OrderedMultiInfo.
  • Also to audit: read() paths that hand a plain dict into a data model field, and the TypedDict bit-field shapes in protocols.schema wherever their values end up stored on a data model.

Convert each one where Info or Data fits, and give the reason for each one left. Pickle and to_dict() compatibility with main must hold. Changing a public type is breaking and needs a versionchanged.

Activity

  1. added this to the PyPCAPKit v1.6 milestone on Nov 3, 2026
  2. added
    refactorRestructuring for its own sake — neither a fix nor a new capability (refactor: prefix)
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Nov 3, 2026
  3. JarryShaw commented on Nov 3, 2026

    @JarryShaw
    OwnerAuthor

    A worker is on this, based on 01f063467. It will audit every direct dict subclass and every plain dict field in protocols.data, then convert each one where Info or Data fits, with pickle and to_dict() compatibility kept against main. wip.

  4. JarryShaw commented on Nov 3, 2026

    @JarryShaw
    OwnerAuthor

    _Registries and MultiDict stay.

  5. JarryShaw commented on Nov 3, 2026

    @JarryShaw
    OwnerAuthor

    Ruling taken: _Registries and MultiDict stay as dict subclasses. The conversion is scoped to FrameRecord and to the plain dict fields in protocols.data, starting with PCAP-NG DSB entries. It also covers any read() path the audit finds handing a plain dict into a data model.

    The worker is already on it, and I've passed this scope to it. wip.

  6. JarryShaw commented on Nov 3, 2026

    @JarryShaw
    OwnerAuthor

    Actually _Registries should move as well.

  7. JarryShaw commented on Nov 3, 2026

    @JarryShaw
    OwnerAuthor

    Ruling taken: _Registries is converted as well. Only MultiDict stays a dict subclass.

    How this fits with the rest: _Registries lives in pcapkit/const/reg/apptype/__init__.py, the file the new lazy-import work rewrites to load SCTP and DCCP lazily, per your in-session ruling. To avoid two workers clobbering one file, its conversion goes into that change. The new issue tracks it. This issue keeps FrameRecord and the plain dict fields in protocols.data.

  8. JarryShaw commented on Nov 3, 2026

    @JarryShaw
    OwnerAuthor

    The worker converted FrameRecord and the PCAP-NG DSB entries, and a Sonnet review passed it. The PR follows once a small fold lands.

    Needs deciding: _EnumRegistry, a defaultdict subclass in protocols/schema/schema.py, is the one direct dict subclass left that no ruling covers. It is the mutable class-level registry that register() writes into.

    1. Leave it. It must stay mutable, which an Info cannot be.
    2. Rework it onto Info or Data, for example by holding an immutable Info and rebuilding it on each register().

    Recommendation: 1. A registry that callers extend at runtime is the kind of genuinely mutable mapping MultiDict is. Going ahead with 1 unless you pick 2.

  9. added
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Nov 3, 2026
  10. moved this from WIP to Needs decision in PyPCAPKiton Nov 3, 2026
  11. JarryShaw commented on Nov 3, 2026

    @JarryShaw
    OwnerAuthor

    The PR is #2734. _EnumRegistry still waits on the decision above.

  12. JarryShaw commented on Nov 3, 2026

    @JarryShaw
    OwnerAuthor

    okay, take 1

  13. JarryShaw commented on Nov 3, 2026

    @JarryShaw
    OwnerAuthor

    Ruling: option 1. _EnumRegistry(defaultdict) stays as it is: a mutable class registry, where a mapping base is warranted. That was the last open question here. #2734 (dict subclasses and data fields) and #2735 (_Registries via #2729) cover the rest, and this closes once both have merged.

  14. removed
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Nov 3, 2026
  15. moved this from Needs decision to WIP in PyPCAPKiton Nov 3, 2026
  16. JarryShaw commented on Nov 3, 2026

    @JarryShaw
    OwnerAuthor

    Closing: #2734 (Info or Data instead of dict subclasses, plus the data-model fields) and #2735 (_Registries as an Info, under #2729) have both merged. The ruling above keeps _EnumRegistry(defaultdict) as it is, so nothing remains open.

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