Enforce string-formatting with f-strings (#10980)
* First third * Styling and fix mistake * Quality * All the rest * Treat %s and %d * typo * Missing ) * Apply suggestions from code review Co-authored-by: Lysandre Debut <lysandre@huggingface.co> Co-authored-by: Lysandre Debut <lysandre@huggingface.co>
This commit is contained in:
@@ -685,7 +685,7 @@ class BatchEncoding(UserDict):
|
||||
# (mfuntowicz: This code is unreachable)
|
||||
# else:
|
||||
# raise ImportError(
|
||||
# "Unable to convert output to tensors format {}".format(tensor_type)
|
||||
# f"Unable to convert output to tensors format {tensor_type}"
|
||||
# )
|
||||
|
||||
# Do the tensor conversion in batch
|
||||
@@ -805,9 +805,7 @@ class SpecialTokensMixin:
|
||||
elif isinstance(value, (str, AddedToken)):
|
||||
setattr(self, key, value)
|
||||
else:
|
||||
raise TypeError(
|
||||
"special token {} has to be either str or AddedToken but got: {}".format(key, type(value))
|
||||
)
|
||||
raise TypeError(f"special token {key} has to be either str or AddedToken but got: {type(value)}")
|
||||
|
||||
def sanitize_special_tokens(self) -> int:
|
||||
"""
|
||||
@@ -872,7 +870,7 @@ class SpecialTokensMixin:
|
||||
assert key in self.SPECIAL_TOKENS_ATTRIBUTES, f"Key {key} is not a special token"
|
||||
|
||||
if self.verbose:
|
||||
logger.info("Assigning %s to the %s key of the tokenizer", value, key)
|
||||
logger.info(f"Assigning {value} to the {key} key of the tokenizer")
|
||||
setattr(self, key, value)
|
||||
|
||||
if key == "additional_special_tokens":
|
||||
@@ -1866,7 +1864,7 @@ class PreTrainedTokenizerBase(SpecialTokensMixin):
|
||||
A tuple of :obj:`str`: The files saved.
|
||||
"""
|
||||
if os.path.isfile(save_directory):
|
||||
logger.error("Provided path ({}) should be a directory, not a file".format(save_directory))
|
||||
logger.error(f"Provided path ({save_directory}) should be a directory, not a file")
|
||||
return
|
||||
os.makedirs(save_directory, exist_ok=True)
|
||||
|
||||
@@ -3137,8 +3135,8 @@ class PreTrainedTokenizerBase(SpecialTokensMixin):
|
||||
if not self.deprecation_warnings.get("sequence-length-is-longer-than-the-specified-maximum", False):
|
||||
logger.warning(
|
||||
"Token indices sequence length is longer than the specified maximum sequence length "
|
||||
"for this model ({} > {}). Running this sequence through the model will result in "
|
||||
"indexing errors".format(len(ids), self.model_max_length)
|
||||
f"for this model ({len(ids)} > {self.model_max_length}). Running this sequence through the model "
|
||||
"will result in indexing errors"
|
||||
)
|
||||
self.deprecation_warnings["sequence-length-is-longer-than-the-specified-maximum"] = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user