From a59588e019a7310de31f38f718fe8959ae2c022c Mon Sep 17 00:00:00 2001 From: liao yinan Date: Tue, 16 Jun 2026 03:41:52 +0800 Subject: [PATCH] fix: mypy strict error on _inv_map union type in _vocab_cache init Add assert self._inv_map is not None before the dict comprehension so mypy can narrow the union type. Also removes the unused type: ignore comment that was on the wrong line. --- tinybpe/tokenizer.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tinybpe/tokenizer.py b/tinybpe/tokenizer.py index ce03adb..41e7c36 100644 --- a/tinybpe/tokenizer.py +++ b/tinybpe/tokenizer.py @@ -153,10 +153,8 @@ def __init__( # so we build it once here and cache the inverse-remapped result. self._vocab_cache: dict[int, bytes] | None = None if bytes_maps is not None: - self._vocab_cache = { - k: self._inv_map(v) - for k, v in self._enc.vocab.items() # type: ignore[union-attr] - } + assert self._inv_map is not None # guaranteed when bytes_maps is set + self._vocab_cache = {k: self._inv_map(v) for k, v in self._enc.vocab.items()} # ------------------------------------------------------------------ # Encoding