Skip to content

Commit 08af591

Browse files
committed
Be more explicit about the cases
1 parent f4af12a commit 08af591

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

barcode/codex.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,14 @@ def _convert_or_buffer(self, char: str) -> int | None:
240240
return code128.C[char]
241241
if char.isdigit():
242242
self._buffer += char
243-
if len(self._buffer) == 2:
244-
value = int(self._buffer)
245-
self._buffer = ""
246-
return value
247-
return None
248-
raise RuntimeError(
249-
f"Character {char} could not be converted in charset {self._charset}."
250-
)
243+
if len(self._buffer) == 1:
244+
# Wait for the second digit to group in pairs
245+
return None
246+
assert len(self._buffer) == 2
247+
value = int(self._buffer)
248+
self._buffer = ""
249+
return value
250+
raise RuntimeError(f"Character {char} could not be converted in charset C.")
251251

252252
def _try_to_optimize(self, encoded: list[int]) -> list[int]:
253253
if encoded[1] in code128.TO:

0 commit comments

Comments
 (0)