spitch 1.34.0__py3-none-any.whl → 1.35.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of spitch might be problematic. Click here for more details.

@@ -16,18 +16,20 @@ from ._utils import (
16
16
  lru_cache,
17
17
  is_mapping,
18
18
  is_iterable,
19
+ is_sequence,
19
20
  )
20
21
  from .._files import is_base64_file_input
22
+ from ._compat import get_origin, is_typeddict
21
23
  from ._typing import (
22
24
  is_list_type,
23
25
  is_union_type,
24
26
  extract_type_arg,
25
27
  is_iterable_type,
26
28
  is_required_type,
29
+ is_sequence_type,
27
30
  is_annotated_type,
28
31
  strip_annotated_type,
29
32
  )
30
- from .._compat import get_origin, model_dump, is_typeddict
31
33
 
32
34
  _T = TypeVar("_T")
33
35
 
@@ -167,6 +169,8 @@ def _transform_recursive(
167
169
 
168
170
  Defaults to the same value as the `annotation` argument.
169
171
  """
172
+ from .._compat import model_dump
173
+
170
174
  if inner_type is None:
171
175
  inner_type = annotation
172
176
 
@@ -184,6 +188,8 @@ def _transform_recursive(
184
188
  (is_list_type(stripped_type) and is_list(data))
185
189
  # Iterable[T]
186
190
  or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
191
+ # Sequence[T]
192
+ or (is_sequence_type(stripped_type) and is_sequence(data) and not isinstance(data, str))
187
193
  ):
188
194
  # dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
189
195
  # intended as an iterable, so we don't transform it.
@@ -262,7 +268,7 @@ def _transform_typeddict(
262
268
  annotations = get_type_hints(expected_type, include_extras=True)
263
269
  for key, value in data.items():
264
270
  if not is_given(value):
265
- # we don't need to include `NotGiven` values here as they'll
271
+ # we don't need to include omitted values here as they'll
266
272
  # be stripped out before the request is sent anyway
267
273
  continue
268
274
 
@@ -329,6 +335,8 @@ async def _async_transform_recursive(
329
335
 
330
336
  Defaults to the same value as the `annotation` argument.
331
337
  """
338
+ from .._compat import model_dump
339
+
332
340
  if inner_type is None:
333
341
  inner_type = annotation
334
342
 
@@ -346,6 +354,8 @@ async def _async_transform_recursive(
346
354
  (is_list_type(stripped_type) and is_list(data))
347
355
  # Iterable[T]
348
356
  or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str))
357
+ # Sequence[T]
358
+ or (is_sequence_type(stripped_type) and is_sequence(data) and not isinstance(data, str))
349
359
  ):
350
360
  # dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually
351
361
  # intended as an iterable, so we don't transform it.
@@ -424,7 +434,7 @@ async def _async_transform_typeddict(
424
434
  annotations = get_type_hints(expected_type, include_extras=True)
425
435
  for key, value in data.items():
426
436
  if not is_given(value):
427
- # we don't need to include `NotGiven` values here as they'll
437
+ # we don't need to include omitted values here as they'll
428
438
  # be stripped out before the request is sent anyway
429
439
  continue
430
440
 
spitch/_utils/_typing.py CHANGED
@@ -6,7 +6,7 @@ from typing_extensions import Required, Annotated, get_args, get_origin
6
6
 
7
7
  from ._utils import lru_cache
8
8
  from .._types import InheritsGeneric
9
- from .._compat import is_union as _is_union
9
+ from ._compat import is_union as _is_union
10
10
 
11
11
 
12
12
  def is_annotated_type(typ: type) -> bool:
@@ -17,6 +17,11 @@ def is_list_type(typ: type) -> bool:
17
17
  return (get_origin(typ) or typ) == list
18
18
 
19
19
 
20
+ def is_sequence_type(typ: type) -> bool:
21
+ origin = get_origin(typ) or typ
22
+ return origin == typing_extensions.Sequence or origin == typing.Sequence or origin == _c_abc.Sequence
23
+
24
+
20
25
  def is_iterable_type(typ: type) -> bool:
21
26
  """If the given type is `typing.Iterable[T]`"""
22
27
  origin = get_origin(typ) or typ
spitch/_utils/_utils.py CHANGED
@@ -21,8 +21,7 @@ from typing_extensions import TypeGuard
21
21
 
22
22
  import sniffio
23
23
 
24
- from .._types import NotGiven, FileTypes, NotGivenOr, HeadersLike
25
- from .._compat import parse_date as parse_date, parse_datetime as parse_datetime
24
+ from .._types import Omit, NotGiven, FileTypes, HeadersLike
26
25
 
27
26
  _T = TypeVar("_T")
28
27
  _TupleT = TypeVar("_TupleT", bound=Tuple[object, ...])
@@ -64,7 +63,7 @@ def _extract_items(
64
63
  try:
65
64
  key = path[index]
66
65
  except IndexError:
67
- if isinstance(obj, NotGiven):
66
+ if not is_given(obj):
68
67
  # no value was provided - we can safely ignore
69
68
  return []
70
69
 
@@ -127,8 +126,8 @@ def _extract_items(
127
126
  return []
128
127
 
129
128
 
130
- def is_given(obj: NotGivenOr[_T]) -> TypeGuard[_T]:
131
- return not isinstance(obj, NotGiven)
129
+ def is_given(obj: _T | NotGiven | Omit) -> TypeGuard[_T]:
130
+ return not isinstance(obj, NotGiven) and not isinstance(obj, Omit)
132
131
 
133
132
 
134
133
  # Type safe methods for narrowing types with TypeVars.
spitch/_version.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  __title__ = "spitch"
4
- __version__ = "1.34.0" # x-release-please-version
4
+ __version__ = "1.35.0" # x-release-please-version
spitch/pagination.py ADDED
@@ -0,0 +1,50 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import List, Generic, TypeVar, Optional
4
+ from typing_extensions import override
5
+
6
+ from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage
7
+
8
+ __all__ = ["SyncFilesCursor", "AsyncFilesCursor"]
9
+
10
+ _T = TypeVar("_T")
11
+
12
+
13
+ class SyncFilesCursor(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
14
+ items: List[_T]
15
+ next_cursor: Optional[str] = None
16
+
17
+ @override
18
+ def _get_page_items(self) -> List[_T]:
19
+ items = self.items
20
+ if not items:
21
+ return []
22
+ return items
23
+
24
+ @override
25
+ def next_page_info(self) -> Optional[PageInfo]:
26
+ next_cursor = self.next_cursor
27
+ if not next_cursor:
28
+ return None
29
+
30
+ return PageInfo(params={"cursor": next_cursor})
31
+
32
+
33
+ class AsyncFilesCursor(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
34
+ items: List[_T]
35
+ next_cursor: Optional[str] = None
36
+
37
+ @override
38
+ def _get_page_items(self) -> List[_T]:
39
+ items = self.items
40
+ if not items:
41
+ return []
42
+ return items
43
+
44
+ @override
45
+ def next_page_info(self) -> Optional[PageInfo]:
46
+ next_cursor = self.next_cursor
47
+ if not next_cursor:
48
+ return None
49
+
50
+ return PageInfo(params={"cursor": next_cursor})
@@ -8,6 +8,14 @@ from .text import (
8
8
  TextResourceWithStreamingResponse,
9
9
  AsyncTextResourceWithStreamingResponse,
10
10
  )
11
+ from .files import (
12
+ FilesResource,
13
+ AsyncFilesResource,
14
+ FilesResourceWithRawResponse,
15
+ AsyncFilesResourceWithRawResponse,
16
+ FilesResourceWithStreamingResponse,
17
+ AsyncFilesResourceWithStreamingResponse,
18
+ )
11
19
  from .speech import (
12
20
  SpeechResource,
13
21
  AsyncSpeechResource,
@@ -30,4 +38,10 @@ __all__ = [
30
38
  "AsyncTextResourceWithRawResponse",
31
39
  "TextResourceWithStreamingResponse",
32
40
  "AsyncTextResourceWithStreamingResponse",
41
+ "FilesResource",
42
+ "AsyncFilesResource",
43
+ "FilesResourceWithRawResponse",
44
+ "AsyncFilesResourceWithRawResponse",
45
+ "FilesResourceWithStreamingResponse",
46
+ "AsyncFilesResourceWithStreamingResponse",
33
47
  ]