Skip to content

Commit 37625fd

Browse files
feat(types): replace List[str] with SequenceNotStr in params
1 parent 856feb3 commit 37625fd

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

src/zeroentropy/_utils/_transform.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
lru_cache,
1717
is_mapping,
1818
is_iterable,
19+
is_sequence,
1920
)
2021
from .._files import is_base64_file_input
2122
from ._typing import (
@@ -24,6 +25,7 @@
2425
extract_type_arg,
2526
is_iterable_type,
2627
is_required_type,
28+
is_sequence_type,
2729
is_annotated_type,
2830
strip_annotated_type,
2931
)
@@ -184,6 +186,8 @@ def _transform_recursive(
184186
(is_list_type(stripped_type) and is_list(data))
185187
# Iterable[T]
186188
or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
189+
# Sequence[T]
190+
or (is_sequence_type(stripped_type) and is_sequence(data) and not isinstance(data, str))
187191
):
188192
# dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
189193
# intended as an iterable, so we don't transform it.
@@ -346,6 +350,8 @@ async def _async_transform_recursive(
346350
(is_list_type(stripped_type) and is_list(data))
347351
# Iterable[T]
348352
or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
353+
# Sequence[T]
354+
or (is_sequence_type(stripped_type) and is_sequence(data) and not isinstance(data, str))
349355
):
350356
# dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
351357
# intended as an iterable, so we don't transform it.

src/zeroentropy/resources/documents.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Dict, List, Union, Optional
5+
from typing import Dict, Union, Optional
66
from typing_extensions import Literal
77

88
import httpx
@@ -15,7 +15,7 @@
1515
document_get_info_list_params,
1616
document_get_page_info_params,
1717
)
18-
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
18+
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr
1919
from .._utils import maybe_transform, async_maybe_transform
2020
from .._compat import cached_property
2121
from .._resource import SyncAPIResource, AsyncAPIResource
@@ -63,7 +63,7 @@ def update(
6363
collection_name: str,
6464
path: str,
6565
index_status: Optional[Literal["not_parsed", "not_indexed"]] | NotGiven = NOT_GIVEN,
66-
metadata: Optional[Dict[str, Union[str, List[str]]]] | NotGiven = NOT_GIVEN,
66+
metadata: Optional[Dict[str, Union[str, SequenceNotStr[str]]]] | NotGiven = NOT_GIVEN,
6767
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
6868
# The extra values given here take precedence over values defined on the client or passed to this method.
6969
extra_headers: Headers | None = None,
@@ -182,7 +182,7 @@ def add(
182182
collection_name: str,
183183
content: document_add_params.Content,
184184
path: str,
185-
metadata: Dict[str, Union[str, List[str]]] | NotGiven = NOT_GIVEN,
185+
metadata: Dict[str, Union[str, SequenceNotStr[str]]] | NotGiven = NOT_GIVEN,
186186
overwrite: bool | NotGiven = NOT_GIVEN,
187187
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
188188
# The extra values given here take precedence over values defined on the client or passed to this method.
@@ -466,7 +466,7 @@ async def update(
466466
collection_name: str,
467467
path: str,
468468
index_status: Optional[Literal["not_parsed", "not_indexed"]] | NotGiven = NOT_GIVEN,
469-
metadata: Optional[Dict[str, Union[str, List[str]]]] | NotGiven = NOT_GIVEN,
469+
metadata: Optional[Dict[str, Union[str, SequenceNotStr[str]]]] | NotGiven = NOT_GIVEN,
470470
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
471471
# The extra values given here take precedence over values defined on the client or passed to this method.
472472
extra_headers: Headers | None = None,
@@ -585,7 +585,7 @@ async def add(
585585
collection_name: str,
586586
content: document_add_params.Content,
587587
path: str,
588-
metadata: Dict[str, Union[str, List[str]]] | NotGiven = NOT_GIVEN,
588+
metadata: Dict[str, Union[str, SequenceNotStr[str]]] | NotGiven = NOT_GIVEN,
589589
overwrite: bool | NotGiven = NOT_GIVEN,
590590
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
591591
# The extra values given here take precedence over values defined on the client or passed to this method.

src/zeroentropy/resources/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from __future__ import annotations
44

5-
from typing import List, Optional
5+
from typing import Optional
66

77
import httpx
88

99
from ..types import model_rerank_params
10-
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
10+
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, SequenceNotStr
1111
from .._utils import maybe_transform, async_maybe_transform
1212
from .._compat import cached_property
1313
from .._resource import SyncAPIResource, AsyncAPIResource
@@ -46,7 +46,7 @@ def with_streaming_response(self) -> ModelsResourceWithStreamingResponse:
4646
def rerank(
4747
self,
4848
*,
49-
documents: List[str],
49+
documents: SequenceNotStr[str],
5050
query: str,
5151
model: str | NotGiven = NOT_GIVEN,
5252
top_n: Optional[int] | NotGiven = NOT_GIVEN,
@@ -126,7 +126,7 @@ def with_streaming_response(self) -> AsyncModelsResourceWithStreamingResponse:
126126
async def rerank(
127127
self,
128128
*,
129-
documents: List[str],
129+
documents: SequenceNotStr[str],
130130
query: str,
131131
model: str | NotGiven = NOT_GIVEN,
132132
top_n: Optional[int] | NotGiven = NOT_GIVEN,

src/zeroentropy/types/document_add_params.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
from __future__ import annotations
44

5-
from typing import Dict, List, Union
5+
from typing import Dict, Union
66
from typing_extensions import Literal, Required, TypeAlias, TypedDict
77

8+
from .._types import SequenceNotStr
9+
810
__all__ = [
911
"DocumentAddParams",
1012
"Content",
@@ -37,7 +39,7 @@ class DocumentAddParams(TypedDict, total=False):
3739
unless `overwrite` is set to `true`.
3840
"""
3941

40-
metadata: Dict[str, Union[str, List[str]]]
42+
metadata: Dict[str, Union[str, SequenceNotStr[str]]]
4143
"""
4244
This is a metadata JSON object that can be used to assign various metadata
4345
attributes to your document. The provided object must match the type
@@ -65,7 +67,7 @@ class ContentAPITextDocument(TypedDict, total=False):
6567

6668

6769
class ContentAPITextPagesDocument(TypedDict, total=False):
68-
pages: Required[List[str]]
70+
pages: Required[SequenceNotStr[str]]
6971
"""The content of this document, as an array of strings.
7072
7173
Each string will be the content of a full page, and can be retrieved using the

src/zeroentropy/types/document_update_params.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
from __future__ import annotations
44

5-
from typing import Dict, List, Union, Optional
5+
from typing import Dict, Union, Optional
66
from typing_extensions import Literal, Required, TypedDict
77

8+
from .._types import SequenceNotStr
9+
810
__all__ = ["DocumentUpdateParams"]
911

1012

@@ -27,7 +29,7 @@ class DocumentUpdateParams(TypedDict, total=False):
2729
failure.
2830
"""
2931

30-
metadata: Optional[Dict[str, Union[str, List[str]]]]
32+
metadata: Optional[Dict[str, Union[str, SequenceNotStr[str]]]]
3133
"""
3234
If this field is provided, the given metadata json will replace the document's
3335
existing metadata json. In other words, if you want to add a new field, you will

src/zeroentropy/types/model_rerank_params.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
from __future__ import annotations
44

5-
from typing import List, Optional
5+
from typing import Optional
66
from typing_extensions import Required, TypedDict
77

8+
from .._types import SequenceNotStr
9+
810
__all__ = ["ModelRerankParams"]
911

1012

1113
class ModelRerankParams(TypedDict, total=False):
12-
documents: Required[List[str]]
14+
documents: Required[SequenceNotStr[str]]
1315
"""The list of documents to rerank. Each document is a string."""
1416

1517
query: Required[str]

0 commit comments

Comments
 (0)