Add missing return type hints to CharBPETokenizer.from_file, train, train_from_iterator - #2325
Open
RudrenduPaul wants to merge 1 commit into
Open
Conversation
…rain_from_iterator
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.
What this PR does
Adds missing return type hints to three methods in
bindings/python/py_src/tokenizers/implementations/char_level_bpe.py:from_file(vocab_filename: str, merges_filename: str, **kwargs) -> "CharBPETokenizer"train(...) -> Nonetrain_from_iterator(...) -> NoneThis follows the same typing-consistency pattern as #2211, which added
the equivalent missing return hints to
BaseTokenizer.save,save_model, andto_str.CharBPETokenizer(aBaseTokenizersubclass) had the identical gap in its own methods: every argument was
already annotated, but the return type was never added.
Why these types are correct
from_fileis a@staticmethodthat returnsCharBPETokenizer(vocab, merges, **kwargs),i.e. a new instance of the class — hence
-> "CharBPETokenizer", matching the quotedself-referential forward-reference convention already used elsewhere in this codebase
(e.g.
Tokenizer.from_file -> "Tokenizer"andBPE.from_file -> "BPE"in the generated.pyistubs).trainandtrain_from_iteratorboth callself._tokenizer.train(...)/self._tokenizer.train_from_iterator(...)without areturnstatement, so they implicitlyreturn
None— hence-> None.Scope note
Checked
gh pr list --repo huggingface/tokenizers --search "char_level_bpe"before starting;no open or closed PR currently touches this file.
No behaviour change
Type-hint-only change on method signatures. No logic, docstrings, or other files were modified.
Testing
ruff check bindings/python/py_src/tokenizers/implementations/char_level_bpe.py— all checks passed.ruff format --check bindings/python/py_src/tokenizers/implementations/char_level_bpe.py— passes, file already formatted.python3 -c "import ast; ast.parse(...)"on the modified file — passes.