-
-
Notifications
You must be signed in to change notification settings - Fork 36
Registries mint a permanent member for every unrecognised value: 1,169 extend_enum sites across 113 registries #775
Copy link
Copy link
Open
Labels
breakingBreaks public-facing behaviour or API (apply alongside the type label)Breaks public-facing behaviour or API (apply alongside the type label)designA design or decision issue: a pattern being decided rather than a defect or a requestA design or decision issue: a pattern being decided rather than a defect or a requestenhancementperfPull requests that improve performance (perf: subject prefix)Pull requests that improve performance (perf: subject prefix)wipWork in flight - a covering PR is open or an agent is actively on itWork in flight - a covering PR is open or an agent is actively on it
Description
Activity
Metadata
Metadata
Assignees
Labels
breakingBreaks public-facing behaviour or API (apply alongside the type label)Breaks public-facing behaviour or API (apply alongside the type label)designA design or decision issue: a pattern being decided rather than a defect or a requestA design or decision issue: a pattern being decided rather than a defect or a requestenhancementperfPull requests that improve performance (perf: subject prefix)Pull requests that improve performance (perf: subject prefix)wipWork in flight - a covering PR is open or an agent is actively on itWork in flight - a covering PR is open or an agent is actively on it
Is your feature request related to a problem? Please describe.
Every registry under
pcapkit/const/turns an unrecognised value into a permanently registered enum member viaaenum.extend_enum, so a process that parses many distinct unassigned values grows its registries without bound. #575 measured the cost on one path — 111 calls and ~13.5% of extraction self time onhttp.pcap— but the mechanism is repo-wide.The maintainer's ruling, verbatim: "i think we should even apply to all other Enum's legit but unbounded values - so that we dont create registered enums out of unrecognised/unregistered values, unless user/caller explicitly created them."
Describe the solution you'd like
Return an unregistered member of the namespace class instead of minting. Measured as viable on
AppType:It satisfies
isinstance, reprs identically to a declared member, and does not grow the registry. NoteAppTypeis aStrEnum(TCP → AppType → StrEnum → str → ReprEnum), so it isstr.__new__; an int-valued registry needsint.__new__instead, andint.__new__(TCP, …)raisesTypeError: TCP is not a subtype of int.Scope, measured by AST over
pcapkit/const/1,169 sites across 113 registries. Both paths mint per value — including the
_missing_declared-range branches, which is not obvious:Those branches are bounded in which ranges they cover, not in how many members they create.
Additional context
#771 implements this for the four
EnumFieldsubclasses only — the parse path, where the measured cost is — and closes #575. This issue is the rest.Three questions to settle before a wide change, none resolved: a value-lookup like
TCP(54321)stays failing since the instance is absent from_value2member_map_;AppType.__eq__/__hash__key on.port, so two unregistered instances for one port compare equal without being identical; and pickling or copying an unregistered member may not survive. Also open is whether this belongs in each registry's_missing_— whereaenumnaturally hooks and where 1,056 of the sites are — rather than at the field layer. The ruling's "unless user/caller explicitly created them" means a directget()call may still register; only paths that never asked for a name should get the unregistered member.