Repository navigation
Add missing return type hints to ByteLevelBPETokenizer.from_file, train, train_from_iterator - #2326
Closed
RudrenduPaul wants to merge 1 commit into
Closed
RudrenduPaul wants to merge 1 commit into
RudrenduPaul wants to merge 1 commit into
Conversation
…in, train_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/byte_level_bpe.py:from_file(vocab_filename: str, merges_filename: str, **kwargs) -> "ByteLevelBPETokenizer"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.ByteLevelBPETokenizer(aBaseTokenizersubclass) has the identical gap: every argument was already annotated,
but the return type was never added to these three methods.
Why these types are correct
from_fileis a@staticmethodthat returnsByteLevelBPETokenizer(vocab, merges, **kwargs), i.e. a new instanceof the class — hence
-> "ByteLevelBPETokenizer", using the quotedself-referential forward-reference convention (the file has no
from __future__ import annotations, and the class name is not yetbound in scope while its own body is being defined). This mirrors the
identical convention already used on the sibling
CharBPETokenizer.from_file -> "CharBPETokenizer"pattern for the samesituation elsewhere in
implementations/.trainandtrain_from_iteratorboth callself._tokenizer.train(...)/self._tokenizer.train_from_iterator(...)without areturnstatement,so they implicitly return
None— hence-> None.Scope note
Ran
gh pr list --repo huggingface/tokenizers --search "byte_level_bpe"and--search "ByteLevelBPETokenizer"before starting; no open or closed PRcurrently touches this file. Re-checked immediately before opening this PR.
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/byte_level_bpe.py— all checks passed.ruff format --check bindings/python/py_src/tokenizers/implementations/byte_level_bpe.py— passes, file already formatted.python3 -c "import ast; ast.parse(...)"on the modified file — passes.