From b118307608caa62a88edb658d9bbdb865ebc0f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Philip=20G=C3=B6pfert?= Date: Wed, 14 Sep 2022 16:56:18 +0200 Subject: [PATCH] Accept `Sequence` instead of `List` This is minor, I know. `tokenize` simply iterates over `texts`, so in addition to `list`, `tuple` is fine. The intended type hint for this is `Sequence`. I am not sure which version of Python this project targets, but judging from the other type hints in this file, I am going to assume `<3.9`. Otherwise, I would suggest importing `Sequence` from `collections.abc` instead of `typing`. --- clip/clip.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clip/clip.py b/clip/clip.py index 257511e1d..535219421 100644 --- a/clip/clip.py +++ b/clip/clip.py @@ -2,7 +2,7 @@ import os import urllib import warnings -from typing import Any, Union, List +from typing import Any, Union, List, Sequence from pkg_resources import packaging import torch @@ -194,7 +194,7 @@ def patch_float(module): return model, _transform(model.input_resolution.item()) -def tokenize(texts: Union[str, List[str]], context_length: int = 77, truncate: bool = False) -> Union[torch.IntTensor, torch.LongTensor]: +def tokenize(texts: Union[str, Sequence[str]], context_length: int = 77, truncate: bool = False) -> Union[torch.IntTensor, torch.LongTensor]: """ Returns the tokenized representation of given input string(s)