spitch 1.24.0__py3-none-any.whl → 1.25.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.

spitch/_base_client.py CHANGED
@@ -1354,9 +1354,9 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
1354
1354
  base_url=base_url,
1355
1355
  # cast to a valid type because mypy doesn't understand our type narrowing
1356
1356
  timeout=cast(Timeout, timeout),
1357
- proxies=proxies,
1358
- transport=transport,
1359
- limits=limits,
1357
+ # proxies=proxies,
1358
+ # transport=transport,
1359
+ # limits=limits,
1360
1360
  follow_redirects=True,
1361
1361
  )
1362
1362
 
spitch/_models.py CHANGED
@@ -64,7 +64,7 @@ from ._compat import (
64
64
  from ._constants import RAW_RESPONSE_HEADER
65
65
 
66
66
  if TYPE_CHECKING:
67
- from pydantic_core.core_schema import ModelField, LiteralSchema, ModelFieldsSchema
67
+ from pydantic_core.core_schema import ModelField, ModelSchema, LiteralSchema, ModelFieldsSchema
68
68
 
69
69
  __all__ = ["BaseModel", "GenericModel"]
70
70
 
@@ -642,15 +642,18 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,
642
642
 
643
643
  def _extract_field_schema_pv2(model: type[BaseModel], field_name: str) -> ModelField | None:
644
644
  schema = model.__pydantic_core_schema__
645
+ if schema["type"] == "definitions":
646
+ schema = schema["schema"]
647
+
645
648
  if schema["type"] != "model":
646
649
  return None
647
650
 
651
+ schema = cast("ModelSchema", schema)
648
652
  fields_schema = schema["schema"]
649
653
  if fields_schema["type"] != "model-fields":
650
654
  return None
651
655
 
652
656
  fields_schema = cast("ModelFieldsSchema", fields_schema)
653
-
654
657
  field = fields_schema["fields"].get(field_name)
655
658
  if not field:
656
659
  return None
@@ -674,7 +677,7 @@ def set_pydantic_config(typ: Any, config: pydantic.ConfigDict) -> None:
674
677
  setattr(typ, "__pydantic_config__", config) # noqa: B010
675
678
 
676
679
 
677
- # our use of subclasssing here causes weirdness for type checkers,
680
+ # our use of subclassing here causes weirdness for type checkers,
678
681
  # so we just pretend that we don't subclass
679
682
  if TYPE_CHECKING:
680
683
  GenericModel = BaseModel
@@ -5,13 +5,15 @@ import base64
5
5
  import pathlib
6
6
  from typing import Any, Mapping, TypeVar, cast
7
7
  from datetime import date, datetime
8
- from typing_extensions import Literal, get_args, override, get_type_hints
8
+ from typing_extensions import Literal, get_args, override, get_type_hints as _get_type_hints
9
9
 
10
10
  import anyio
11
11
  import pydantic
12
12
 
13
13
  from ._utils import (
14
14
  is_list,
15
+ is_given,
16
+ lru_cache,
15
17
  is_mapping,
16
18
  is_iterable,
17
19
  )
@@ -108,6 +110,7 @@ def transform(
108
110
  return cast(_T, transformed)
109
111
 
110
112
 
113
+ @lru_cache(maxsize=8096)
111
114
  def _get_annotated_type(type_: type) -> type | None:
112
115
  """If the given type is an `Annotated` type then it is returned, if not `None` is returned.
113
116
 
@@ -126,7 +129,7 @@ def _get_annotated_type(type_: type) -> type | None:
126
129
  def _maybe_transform_key(key: str, type_: type) -> str:
127
130
  """Transform the given `data` based on the annotations provided in `type_`.
128
131
 
129
- Note: this function only looks at `Annotated` types that contain `PropertInfo` metadata.
132
+ Note: this function only looks at `Annotated` types that contain `PropertyInfo` metadata.
130
133
  """
131
134
  annotated_type = _get_annotated_type(type_)
132
135
  if annotated_type is None:
@@ -142,6 +145,10 @@ def _maybe_transform_key(key: str, type_: type) -> str:
142
145
  return key
143
146
 
144
147
 
148
+ def _no_transform_needed(annotation: type) -> bool:
149
+ return annotation == float or annotation == int
150
+
151
+
145
152
  def _transform_recursive(
146
153
  data: object,
147
154
  *,
@@ -184,6 +191,15 @@ def _transform_recursive(
184
191
  return cast(object, data)
185
192
 
186
193
  inner_type = extract_type_arg(stripped_type, 0)
194
+ if _no_transform_needed(inner_type):
195
+ # for some types there is no need to transform anything, so we can get a small
196
+ # perf boost from skipping that work.
197
+ #
198
+ # but we still need to convert to a list to ensure the data is json-serializable
199
+ if is_list(data):
200
+ return data
201
+ return list(data)
202
+
187
203
  return [_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]
188
204
 
189
205
  if is_union_type(stripped_type):
@@ -245,6 +261,11 @@ def _transform_typeddict(
245
261
  result: dict[str, object] = {}
246
262
  annotations = get_type_hints(expected_type, include_extras=True)
247
263
  for key, value in data.items():
264
+ if not is_given(value):
265
+ # we don't need to include `NotGiven` values here as they'll
266
+ # be stripped out before the request is sent anyway
267
+ continue
268
+
248
269
  type_ = annotations.get(key)
249
270
  if type_ is None:
250
271
  # we do not have a type annotation for this field, leave it as is
@@ -332,6 +353,15 @@ async def _async_transform_recursive(
332
353
  return cast(object, data)
333
354
 
334
355
  inner_type = extract_type_arg(stripped_type, 0)
356
+ if _no_transform_needed(inner_type):
357
+ # for some types there is no need to transform anything, so we can get a small
358
+ # perf boost from skipping that work.
359
+ #
360
+ # but we still need to convert to a list to ensure the data is json-serializable
361
+ if is_list(data):
362
+ return data
363
+ return list(data)
364
+
335
365
  return [await _async_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]
336
366
 
337
367
  if is_union_type(stripped_type):
@@ -393,6 +423,11 @@ async def _async_transform_typeddict(
393
423
  result: dict[str, object] = {}
394
424
  annotations = get_type_hints(expected_type, include_extras=True)
395
425
  for key, value in data.items():
426
+ if not is_given(value):
427
+ # we don't need to include `NotGiven` values here as they'll
428
+ # be stripped out before the request is sent anyway
429
+ continue
430
+
396
431
  type_ = annotations.get(key)
397
432
  if type_ is None:
398
433
  # we do not have a type annotation for this field, leave it as is
@@ -400,3 +435,13 @@ async def _async_transform_typeddict(
400
435
  else:
401
436
  result[_maybe_transform_key(key, type_)] = await _async_transform_recursive(value, annotation=type_)
402
437
  return result
438
+
439
+
440
+ @lru_cache(maxsize=8096)
441
+ def get_type_hints(
442
+ obj: Any,
443
+ globalns: dict[str, Any] | None = None,
444
+ localns: Mapping[str, Any] | None = None,
445
+ include_extras: bool = False,
446
+ ) -> dict[str, Any]:
447
+ return _get_type_hints(obj, globalns=globalns, localns=localns, include_extras=include_extras)
spitch/_utils/_typing.py CHANGED
@@ -4,6 +4,7 @@ from typing import Any, TypeVar, Iterable, cast
4
4
  from collections import abc as _c_abc
5
5
  from typing_extensions import Required, Annotated, get_args, get_origin
6
6
 
7
+ from ._utils import lru_cache
7
8
  from .._types import InheritsGeneric
8
9
  from .._compat import is_union as _is_union
9
10
 
@@ -37,6 +38,7 @@ def is_typevar(typ: type) -> bool:
37
38
 
38
39
 
39
40
  # Extracts T from Annotated[T, ...] or from Required[Annotated[T, ...]]
41
+ @lru_cache(maxsize=8096)
40
42
  def strip_annotated_type(typ: type) -> type:
41
43
  if is_required_type(typ) or is_annotated_type(typ):
42
44
  return strip_annotated_type(cast(type, get_args(typ)[0]))
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.24.0" # x-release-please-version
4
+ __version__ = "1.25.0" # x-release-please-version
@@ -1,12 +1,11 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.3
2
2
  Name: spitch
3
- Version: 1.24.0
3
+ Version: 1.25.0
4
4
  Summary: The official Python library for the spitch API
5
5
  Project-URL: Homepage, https://github.com/spi-tch/spitch-python
6
6
  Project-URL: Repository, https://github.com/spi-tch/spitch-python
7
7
  Author-email: Spitch <dev@spitch.app>
8
- License-Expression: Apache-2.0
9
- License-File: LICENSE
8
+ License: Apache-2.0
10
9
  Classifier: Intended Audience :: Developers
11
10
  Classifier: License :: OSI Approved :: Apache Software License
12
11
  Classifier: Operating System :: MacOS
@@ -114,7 +113,7 @@ Typed requests and responses provide autocomplete and documentation within your
114
113
 
115
114
  ## File uploads
116
115
 
117
- Request parameters that correspond to file uploads can be passed as `bytes`, a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
116
+ Request parameters that correspond to file uploads can be passed as `bytes`, or a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
118
117
 
119
118
  ```python
120
119
  from pathlib import Path
@@ -1,17 +1,17 @@
1
1
  spitch/__init__.py,sha256=mBQhmNu88PeR66Zmw9atnzuU8f1mpSPcW7vn-EeSikE,2399
2
- spitch/_base_client.py,sha256=Xz0U_KB2_i2Cj9_xhL1VFGrt___EU302p01YzAUzdJE,65080
2
+ spitch/_base_client.py,sha256=oORuab7liaQOg-Ud7teTgIfnBZVflIa8LfQA4BWTyog,65086
3
3
  spitch/_client.py,sha256=53FDDffn_8d-95rmM7-awLEUo9h_K2563fOmQm6qL-I,15451
4
4
  spitch/_compat.py,sha256=fQkXUY7reJc8m_yguMWSjHBfO8lNzw4wOAxtkhP9d1Q,6607
5
5
  spitch/_constants.py,sha256=S14PFzyN9-I31wiV7SmIlL5Ga0MLHxdvegInGdXH7tM,462
6
6
  spitch/_exceptions.py,sha256=xsQtKJTiIdz2X1bQDQFZcSW7WBofLazdQm9nMCyPEVM,3220
7
7
  spitch/_files.py,sha256=wV8OmI8oHeNVRtF-7aAEu22jtRG4FzjOioE8lBp-jNA,3617
8
- spitch/_models.py,sha256=l6MV_1qor7alt-wmx365DEIjAUYGxkrbwc2slEkyJ-I,28765
8
+ spitch/_models.py,sha256=hss4ZeAKZvg4pgBAlpn4iQ-IEERaInyjuGS3Nr8y5Rw,28892
9
9
  spitch/_qs.py,sha256=AOkSz4rHtK4YI3ZU_kzea-zpwBUgEY8WniGmTPyEimc,4846
10
10
  spitch/_resource.py,sha256=TLFPcOOmtxZOQLh3XCNPB_BdrQpp0MIYoKoH52aRAu8,1100
11
11
  spitch/_response.py,sha256=3pGMe_eI_h4UPlyp8v6Xn_hu3Lv2i8KGnmKGZ1ZlMyc,28691
12
12
  spitch/_streaming.py,sha256=5SpId2EIfF8Ee8UUYmJxqgHUGP1ZdHCUHhHCdNJREFA,10100
13
13
  spitch/_types.py,sha256=uuSZot9wXgdAMJzfF3raLmt3DvhThG7skqUC98_Dm1k,6167
14
- spitch/_version.py,sha256=T_6UR84JJ-VvKT_HKAkEtxfEcJCjMW-_55q3IGQ9kCg,159
14
+ spitch/_version.py,sha256=ocswzkp59gFl77_040xvhERS-5cf1enlNPeIbnISDs4,159
15
15
  spitch/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  spitch/_utils/__init__.py,sha256=k266EatJr88V8Zseb7xUimTlCeno9SynRfLwadHP1b4,2016
17
17
  spitch/_utils/_logs.py,sha256=ApRyYK_WgZfEr_ygBUBXWMlTgeMr2tdNOGlH8jE4oJc,774
@@ -19,8 +19,8 @@ spitch/_utils/_proxy.py,sha256=z3zsateHtb0EARTWKk8QZNHfPkqJbqwd1lM993LBwGE,1902
19
19
  spitch/_utils/_reflection.py,sha256=ZmGkIgT_PuwedyNBrrKGbxoWtkpytJNU1uU4QHnmEMU,1364
20
20
  spitch/_utils/_streams.py,sha256=SMC90diFFecpEg_zgDRVbdR3hSEIgVVij4taD-noMLM,289
21
21
  spitch/_utils/_sync.py,sha256=TpGLrrhRNWTJtODNE6Fup3_k7zrWm1j2RlirzBwre-0,2862
22
- spitch/_utils/_transform.py,sha256=tsSFOIZ7iczaUsMSGBD_iSFOOdUyT2xtkcq1xyF0L9o,13986
23
- spitch/_utils/_typing.py,sha256=tFbktdpdHCQliwzGsWysgn0P5H0JRdagkZdb_LegGkY,3838
22
+ spitch/_utils/_transform.py,sha256=n7kskEWz6o__aoNvhFoGVyDoalNe6mJwp-g7BWkdj88,15617
23
+ spitch/_utils/_typing.py,sha256=r5qmf4o7lLpjnklQ9UnQY6op6ipr7qq1GyLroPalH7g,3893
24
24
  spitch/_utils/_utils.py,sha256=8UmbPOy_AAr2uUjjFui-VZSrVBHRj6bfNEKRp5YZP2A,12004
25
25
  spitch/lib/.keep,sha256=wuNrz-5SXo3jJaJOJgz4vFHM41YH_g20F5cRQo0vLes,224
26
26
  spitch/resources/__init__.py,sha256=KT6rAvIlWHQk9QdM4Jp8ABziKILaBrrtiO7LCB5Wa5E,976
@@ -34,7 +34,7 @@ spitch/types/text_tone_mark_params.py,sha256=63P5VElxanYkDP1ZLEuQt97JSgVpMCaAo4W
34
34
  spitch/types/text_tone_mark_response.py,sha256=WGxZsBxLceZ03VM5dafZshp6azdDxpNHcJHhBX7A5DY,277
35
35
  spitch/types/text_translate_params.py,sha256=rU5hbTyBaP5L_akmgswHoNLcTKWN0Gz1kL1yt3EQL44,404
36
36
  spitch/types/text_translate_response.py,sha256=Az3QSpvarlCNTiB7uVzMH21YoWHWJMBEvgdKgVJZW4M,279
37
- spitch-1.24.0.dist-info/METADATA,sha256=TqFUgeMC-YHY9CzJ9ZKCXmD4lLmg-UtAkfc4wIKE4yo,13285
38
- spitch-1.24.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
39
- spitch-1.24.0.dist-info/licenses/LICENSE,sha256=C0lDWY-no8IxmnqzQA9BA7Z8jeh_bogVPfeWSgeDDcc,11336
40
- spitch-1.24.0.dist-info/RECORD,,
37
+ spitch-1.25.0.dist-info/METADATA,sha256=S7-_2GNwJJJiBmJZZed3UIjekuCqxNkWpJkzvmNCDbQ,13255
38
+ spitch-1.25.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
39
+ spitch-1.25.0.dist-info/licenses/LICENSE,sha256=C0lDWY-no8IxmnqzQA9BA7Z8jeh_bogVPfeWSgeDDcc,11336
40
+ spitch-1.25.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.27.0
2
+ Generator: hatchling 1.26.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any