Fixed KeyError on bare crc16 and crc codecs#47
Open
gaoflow wants to merge 1 commit into
Open
Conversation
The width-16 and crc-a variant tables were the only ones without a '' default entry, so encode(data, "crc16") and bare "crc" raised KeyError: '' instead of resolving like every other width. Default them to CRC-16/ARC and CRC-A respectively (both already present as named aliases).
|
Tick the box to add this pull request to the merge queue (same as
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
codext.encode(data, "crc16")— the most common CRC width — raisesKeyError: '', and so does a barecrc, while every other width resolves fine with a bare name:Root cause: in
checksums/crc.pya barecrcNresolves to the''key of that width's variant table. Every width defines that''default except width 16, and the top-level crc-a table only has'a'— so those two are the only bare names that crash.I checked the rest of the table is sound:
crc("123456789", …)matches the storedcheckvalue for all 162 registered variants (0 mismatches), so the only defect is the two missing defaults. This adds them:crc16→ CRC-16/ARC (poly0x8005) = reveng's canonical "CRC-16", identical to the existingarc/ibm/lhaentries →bb3dcrc→ CRC-A, identical tocrca→bf05The test extends the existing checksum test with an invariant that every registered
crc<width>(and barecrc) resolves without a variant suffix and equals its defaultcheck, so a future width added without a''default would be caught.If you'd rather keep bare
crc16explicit, the alternative is to raise a clearValueError("ambiguous, specify a variant") instead ofKeyError— I defaulted it to stay consistent with the other 16 widths.