Cleanup of barcode.codex._convert#234
Merged
WhyNotHugo merged 6 commits intoWhyNotHugo:mainfrom Aug 30, 2025
Merged
Conversation
Contributor
Author
Contributor
Author
|
@WhyNotHugo, I rebased to resolve the merge conflicts. Zero urgency on this. |
e72b03d to
85acbda
Compare
Owner
|
Rebased and applied. Thanks. |
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.
Most invocations of
_convertare guaranteed to not handle digits in charset C. Handling extra digits in charset C introduces extra complexity due to grouping of pairs of digits, which is handled by_buffer. (I rename_bufferto_digit_bufferfor clarity.)In order to isolate the complexity and ease type hinting, I restrict
_convertto return onlyintand raise an informative exception whenever the buffer is triggered. Correspondingly I introduce a function_convert_or_bufferreturningint | Noneto handle the full case when_digit_buffermight be used.There is just one single place (
_build) where_convert_or_bufferis necessary rather than_convert.Reasons why
_convertis safe to use in all other invocations:_new_charsetit's used to switch charset, so it won't be used on a digit._maybe_switch_charsetand_buildit's used to flush the buffer immediately after switching to either charset A or B, so the charset cannot be C._convert_or_bufferI explicitly check before invoking that the charset isn't C.This makes it clear why only the invocation in
_buildneeds to handle theNonereturn type. (IMO it's pretty tricky to deduce this if you're not already familiar with the implementation.)