Skip to content

Commit

Permalink
Add typing.overload for convert_ids_tokens (huggingface#6637)
Browse files Browse the repository at this point in the history
* add overload for type checker

* black
  • Loading branch information
tamuhey authored and fabiocapsouza committed Nov 15, 2020
1 parent 4831ea3 commit 87d3a5c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/transformers/tokenization_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import logging
import re
import unicodedata
from typing import Any, Dict, List, Optional, Tuple, Union
from typing import Any, Dict, List, Optional, Tuple, Union, overload

from .file_utils import add_end_docstrings
from .tokenization_utils_base import (
Expand Down Expand Up @@ -657,6 +657,14 @@ def get_special_tokens_mask(
"""
return [0] * ((len(token_ids_1) if token_ids_1 else 0) + len(token_ids_0))

@overload
def convert_ids_to_tokens(self, ids: int, skip_special_tokens: bool = False) -> str:
...

@overload
def convert_ids_to_tokens(self, ids: List[int], skip_special_tokens: bool = False) -> List[str]:
...

def convert_ids_to_tokens(
self, ids: Union[int, List[int]], skip_special_tokens: bool = False
) -> Union[str, List[str]]:
Expand Down

0 comments on commit 87d3a5c

Please sign in to comment.