Skip to content

EnumRegistry.get() mints through its default, contradicting its own "It never mints" contract #864

Description

@JarryShaw

EnumRegistry.get's docstring says "It never mints. Registering a member is register's job and nobody else's, which is the ruling #775 exists to carry out" (pcapkit/corekit/enum.py:267-270). It does mint, today, on a shipped registry — both the str branch (:297) and the value branch (:303) end in return cls(default), which reaches _missing_.

Measured on main (6b333d7e4), throwaway process, pcapkit.__file__ asserted inside a clean worktree:

len before      : 160
get(0x1234, 0x0888) -> <EtherType.Xyplex_0x0888: 2184>
len after       : 161
MINTED          : ['Xyplex_0x0888']

0x1234 is in no _missing_ range, so the lookup falls to the default; 0x0888 is in the Xyplex range, which mints by the #775 ruling. So a failed lookup permanently grows the registry. This survives #861 for the three registries that still mint — EtherType (52 branches), Socket (1), CGAType (1).

Needs a ruling, because both readings are defensible. Either (a) a caller who names 0x0888 as a fallback has "explicitly" asked for that member, so minting is correct and the docstring is simply wrong; or (b) a fallback is a value to resolve, not a request to register, so get should resolve the default through the non-minting path (_value2member_map_, then _unregistered_member) and cls(default) is the defect.

My lean is (b): #775's wording is "so that we dont create registered enums out of unrecognised/unregistered values, unless user/caller explicitly created them", and passing a fallback is not creating one. But (b) changes behaviour on a shipped path, so it is not mine to decide.

Found by the #863 cross-review, which scoped it to str-valued registries; the int path above is the live case and is wider than that. Pre-existing — cls(default) is identical on main before #863.

Activity

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

    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)designA design or decision issue: a pattern being decided rather than a defect or a request

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions