Skip to content

refactor(const,protocols): reparent the last seven non-registry enums onto EnumLookup #930

Description

@JarryShaw

#877's phase 2 is half done. #921 re-parented 17 of the 24 non-registry enumerations onto EnumLookup; seven are still outside it, and #877 is closed, so nothing tracks them.

Measured on 4f3d43df7 by walking every importable pcapkit.* module (vendor templates excluded) and filtering on issubclass(cls, EnumLookup):

pcapkit.const.ftp.command.CommandType
pcapkit.const.ftp.command.ConformanceRequirement
pcapkit.protocols.internet.esp.ESPStatus
pcapkit.protocols.internet.mh.FastBindingAcknowledgmentStatus
pcapkit.protocols.internet.mh.IPv6AddressPrefixCode
pcapkit.protocols.internet.mh.LMAAddressCode
pcapkit.protocols.internet.mh.LocalizedRoutingStatus

Why these seven and not the other 17. They were deliberately deferred, not overlooked. At the time #921 was written, const/ftp/command.py was held by #913 and esp.py / mh.py by #904 — so widening the in-flight worker's scope would have collided. All three blockers have since merged (1f433..., b3551cb63), so the contention is gone.

Scope

Re-parent each from (EnumBase,) to (EnumLookup, EnumBase), the same change #921 made for the other 17. #921's own PR is the pattern to follow, including its test file tests/corekit/test_enum_lookup_reparent_877_unit.py.

Two things #921 learned that apply here:

  • EnumLookup.get is a @classmethod. Any existing get override that is a @staticmethod cannot call super().get(...) — it raises RuntimeError: super(): no arguments. Check each of the seven for an override before assuming a bare re-parent suffices.
  • Member-table sizes must not change. Verify (len(__members__), len(list(cls))) before and after for each, since a re-parent that silently mints a member is the defect this programme exists to prevent.

Note the exception contract has moved since #921: EnumLookup.get now raises EnumKeyError / EnumValueError from pcapkit.utilities.exceptions (#923, merged as 4f3d43df7), so a name miss is KeyError-derived and raised quietly. mh.py's two except KeyError: raise EnumKeyError(...) conversions already reflect that and should be left alone.

Not blocked. No open PR touches these three files — #657 is docs-only and merges last.

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

    enhancementIssues requesting a new capability (set by the feature request template)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