|
4 | 4 | import sys |
5 | 5 | from collections.abc import ( |
6 | 6 | Callable, |
| 7 | + Collection, |
7 | 8 | Iterator, |
8 | 9 | Sequence, |
9 | 10 | ) |
@@ -148,13 +149,13 @@ def __post_init__(self) -> None: |
148 | 149 | object.__setattr__(self, "items", tuple(unique_items)) |
149 | 150 |
|
150 | 151 | @classmethod |
151 | | - def from_values(cls, values: Sequence[str], *, is_sorted: bool = False) -> Self: |
152 | | - """Create a completion results instance from a sequence of arbitrary objects. |
| 152 | + def from_values(cls, values: Iterator[Any], *, is_sorted: bool = False) -> Self: |
| 153 | + """Create a CompletionItem instance from arbitrary objects. |
153 | 154 |
|
154 | 155 | :param values: the raw objects (e.g. strs, ints, Paths) to be converted into CompletionItems. |
155 | 156 | :param is_sorted: whether the values are already in the desired order. |
156 | 157 | """ |
157 | | - items = [CompletionItem(value=v) for v in values] |
| 158 | + items = [v if isinstance(v, CompletionItem) else CompletionItem(value=v) for v in values] |
158 | 159 | return cls(items=items, is_sorted=is_sorted) |
159 | 160 |
|
160 | 161 | def to_strings(self) -> tuple[str, ...]: |
@@ -244,7 +245,7 @@ class Completions(CompletionResultsBase): |
244 | 245 | _quote_char: str = "" |
245 | 246 |
|
246 | 247 |
|
247 | | -def all_display_numeric(items: Sequence[CompletionItem]) -> bool: |
| 248 | +def all_display_numeric(items: Collection[CompletionItem]) -> bool: |
248 | 249 | """Return True if items is non-empty and every item.display is a numeric string.""" |
249 | 250 | return bool(items) and all(NUMERIC_RE.match(item.display) for item in items) |
250 | 251 |
|
|
0 commit comments