-
-
Notifications
You must be signed in to change notification settings - Fork 36
const: make EnumRegistry.get's NO_DEFAULT a sentinel object, not -1 #857
Copy link
Copy link
Closed
Labels
constRegenerated IANA or vendor constant tables; members keep their numeric valuesRegenerated IANA or vendor constant tables; members keep their numeric valuesenhancementIssues requesting a new capability (set by the feature request template)Issues requesting a new capability (set by the feature request template)refactorRestructuring for its own sake — neither a fix nor a new capability (refactor: prefix)Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix)
Milestone
Description
Activity
Metadata
Metadata
Assignees
Labels
constRegenerated IANA or vendor constant tables; members keep their numeric valuesRegenerated IANA or vendor constant tables; members keep their numeric valuesenhancementIssues requesting a new capability (set by the feature request template)Issues requesting a new capability (set by the feature request template)refactorRestructuring for its own sake — neither a fix nor a new capability (refactor: prefix)Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix)
Projects
- StatusShow more project fieldsDone
Is your feature request related to a problem? Please describe.
EnumRegistry.get's no default marker is the magic value-1, named asNO_DEFAULTinpcapkit/corekit/enums.py:64but still just anint. Raised by @JarryShaw on #855: "I'm wondering if we shouldchange the NO_DEFAULT to a sentinel object."
There is no correctness bug today, measured on #855's head
cb7eb0d94:(last line from
grep -rhoE '^ [A-Z_0-9]+ = -?[0-9]+$' pcapkit/const | grep -oE '\-?[0-9]+$' | sort -n | head)The wart it does have: the test is
default == NO_DEFAULT, and-1.0 == -1isTrue, soget(key, -1.0)silently means no default rather than defaulting to
-1.0. Degenerate — no caller passes a float — but it isthe class of thing a sentinel makes impossible.
Describe the solution you'd like
NO_DEFAULT = object(), with the two comparisons atenums.py:140and:146becomingisrather than==. Anobject()cannot compare equal to anything a caller might pass, and no call site needs a new import, sincedefaultkeeps its default value. A subclass or an enum member would both be worse — each can still compare equalto something.
Describe alternatives you've considered
Doing it inside #855, which is where it was raised. Rejected: #855 already leaves
pcapkit.constwith twocontradictory
registercontracts — the base guards an already-registered value, the 105 generated registriesstill silently alias — and changing only the base's
getwould add a second base-vs-generated divergence.Additional context
This belongs to the tier of #775 that rewrites
pcapkit/vendor/default.pyand regenerates, because that is theonly place the base and the 108 generated registries change atomically. Fold it in beside the
register()guardresidue, which has the identical shape.
Deferred by @JarryShaw on #855: "Okay let's save the sentinel change to an issue (existing or new)." Also
recorded as a scoped item on #775.