Skip to content

Split ENCODINGS_LOOKUP into name and prefix-code maps - #61

Merged
acul71 merged 1 commit into
masterfrom
refactor/issue-44-encodings-lookup
Oct 2, 2026
Merged

acul71 merged 1 commit into
masterfrom
refactor/issue-44-encodings-lookup

Conversation

@acul71

@acul71 acul71 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes ENCODINGS_LOOKUP mixes string and bytes keys in the same dict #44
  • Introduces _ENCODINGS_BY_NAME and _ENCODINGS_BY_CODE; keeps ENCODINGS_LOOKUP as a backward-compatible mixed alias
  • Name-based APIs (encode, is_encoding_supported, get_encoding_info, Encoder) only accept encoding names
  • Prefix resolution stays on get_codec / decode
  • Updates API docs and adds regression tests

Demo / evidence

is_encoding_supported('base16'): True
is_encoding_supported(b'f'): False
encode(b'f', ...): UnsupportedEncodingError Encoding b'f' not supported.
get_codec(b'f68656c6c6f').encoding: base16
get_codec(emoji).encoding: base256emoji

Explanation: Before this change, mixed keys made is_encoding_supported(b"f") return True. After the split, name APIs reject prefix bytes while get_codec still resolves single-byte and emoji prefixes.

Test plan

  • make lint
  • make typecheck
  • make test
  • make docs-ci
  • Manual before/after snippet above

Made with Cursor

@acul71

acul71 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Demo logs (name vs prefix-code)

is_encoding_supported('base16'): True
is_encoding_supported(b'f'): False
encode(b'f', ...): UnsupportedEncodingError Encoding b'f' not supported.
get_codec(b'f68656c6c6f').encoding: base16
get_codec(emoji).encoding: base256emoji

Name-based APIs no longer treat prefix bytes as encoding names; get_codec still resolves prefixes including base256emoji.

@acul71

acul71 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@sumanjeet0012 Could you please review this PR when you have a chance? Thanks!

Keep name-based APIs on encoding names only and resolve multibase
prefixes through a dedicated code map, fixing mixed-key lookup confusion.

Co-authored-by: Cursor <cursoragent@cursor.com>
@acul71
acul71 force-pushed the refactor/issue-44-encodings-lookup branch from 60d717f to ce0186e Compare October 2, 2026 07:49
@acul71
acul71 merged commit fb19ddb into master Oct 2, 2026
21 checks passed
@acul71
acul71 deleted the refactor/issue-44-encodings-lookup branch October 2, 2026 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENCODINGS_LOOKUP mixes string and bytes keys in the same dict

1 participant