"...git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "80377eb018c077dba434bc8e7912bcaed3a64d09"
Unverified Commit a0c08aa3 authored by MocktaiLEngineer's avatar MocktaiLEngineer Committed by GitHub
Browse files

Assertions to exceptions (#13692)



* Raise exceptions instead of using assertions for control flow #12789

* # coding=utf-8

* Raise exceptions instead of using assertions for control flow

* Raise exceptions instead of using assertions for control flow

* Update src/transformers/tokenization_utils.py

Raise exceptions instead of using assertions for control flow
Co-authored-by: default avatarSuraj Patil <surajp815@gmail.com>

* Update src/transformers/tokenization_utils.py

Raise exceptions instead of using assertions for control flow
Co-authored-by: default avatarSylvain Gugger <35901082+sgugger@users.noreply.github.com>

* Raise exceptions instead of using assertions for control flow

* test

* Raise exceptions instead of using assertions for control flow
Co-authored-by: default avatarMocktaiLEngineer <kavinarasu22@gmail.com>
Co-authored-by: default avatarSuraj Patil <surajp815@gmail.com>
Co-authored-by: default avatarSylvain Gugger <35901082+sgugger@users.noreply.github.com>
parent 27d46397
...@@ -362,7 +362,8 @@ class PreTrainedTokenizer(PreTrainedTokenizerBase): ...@@ -362,7 +362,8 @@ class PreTrainedTokenizer(PreTrainedTokenizerBase):
tokens_to_add = [] tokens_to_add = []
for token in new_tokens: for token in new_tokens:
assert isinstance(token, str) if not isinstance(token, str):
raise TypeError(f"Token {token} is not a string but a {type(token)}.")
if not special_tokens and hasattr(self, "do_lower_case") and self.do_lower_case: if not special_tokens and hasattr(self, "do_lower_case") and self.do_lower_case:
token = token.lower() token = token.lower()
if ( if (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment