diff --git a/examples/example.py b/examples/example.py index 7606b78..53b13f8 100755 --- a/examples/example.py +++ b/examples/example.py @@ -5,16 +5,14 @@ from spitch import Spitch -client = Spitch(api_key=os.getenv('SPITCH_API_KEY')) +client = Spitch(api_key=os.getenv("SPITCH_API_KEY")) speech_file_path = Path(__file__).parent / "audio.mp3" def main() -> None: start_time = time.time() with client.speech.with_streaming_response.generate( - language="yo", - text="Bawo ni ololufe?", - voice="funmi" + language="yo", text="Bawo ni ololufe?", voice="funmi" ) as speech: print(f"Time to first byte: {int((time.time() - start_time) * 1000)}ms") speech.stream_to_file(speech_file_path) diff --git a/requirements-dev.lock b/requirements-dev.lock index 1bb189c..67c0b15 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -38,7 +38,7 @@ h11==0.14.0 # via httpcore httpcore==1.0.2 # via httpx -httpx==0.28.1 +httpx==0.27.2 # via respx # via spitch idna==3.4 @@ -90,6 +90,7 @@ six==1.16.0 # via python-dateutil sniffio==1.3.0 # via anyio + # via httpx # via spitch time-machine==2.9.0 tomli==2.0.2 @@ -100,6 +101,7 @@ typing-extensions==4.12.2 # via mypy # via pydantic # via pydantic-core + # via pyright # via spitch virtualenv==20.24.5 # via nox diff --git a/requirements.lock b/requirements.lock index 05d014c..08d01f9 100644 --- a/requirements.lock +++ b/requirements.lock @@ -26,7 +26,7 @@ h11==0.14.0 # via httpcore httpcore==1.0.2 # via httpx -httpx==0.28.1 +httpx==0.27.2 # via spitch idna==3.4 # via anyio @@ -37,6 +37,7 @@ pydantic-core==2.23.4 # via pydantic sniffio==1.3.0 # via anyio + # via httpx # via spitch typing-extensions==4.12.2 # via anyio diff --git a/src/spitch/_base_client.py b/src/spitch/_base_client.py index e7119ca..a07b15c 100644 --- a/src/spitch/_base_client.py +++ b/src/spitch/_base_client.py @@ -852,7 +852,7 @@ def __init__( self._client = http_client or SyncHttpxClientWrapper( base_url=base_url, # cast to a valid type because mypy doesn't understand our type narrowing - timeout=cast(Timeout, timeout) + timeout=cast(Timeout, timeout), ) def is_closed(self) -> bool: diff --git a/src/spitch/_response.py b/src/spitch/_response.py index daddf0a..0667317 100644 --- a/src/spitch/_response.py +++ b/src/spitch/_response.py @@ -210,8 +210,8 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T: raise ValueError(f"Subclasses of httpx.Response cannot be passed to `cast_to`") return cast(R, response) - if inspect.isclass(origin) and not issubclass(origin, BaseModel) and issubclass(origin, pydantic.BaseModel): - raise TypeError("Pydantic models must subclass our base model type, e.g. `from openai import BaseModel`") + if inspect.isclass(origin) and not issubclass(origin, BaseModel) and issubclass(origin, pydantic.BaseModel): # type: ignore + raise TypeError("Pydantic models must subclass our base model type, e.g. `from spitch import BaseModel`") if ( cast_to is not object @@ -261,7 +261,6 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T: ) - class APIResponse(BaseAPIResponse[R]): @overload def parse(self, *, to: type[_T]) -> _T: ... diff --git a/src/spitch/resources/speech.py b/src/spitch/resources/speech.py index 3e00be1..f47d1cb 100644 --- a/src/spitch/resources/speech.py +++ b/src/spitch/resources/speech.py @@ -346,10 +346,7 @@ class SpeechResourceWithStreamingResponse: def __init__(self, speech: SpeechResource) -> None: self._speech = speech - self.generate = to_custom_streamed_response_wrapper( - speech.generate, - StreamedBinaryAPIResponse - ) + self.generate = to_custom_streamed_response_wrapper(speech.generate, StreamedBinaryAPIResponse) self.transcribe = to_streamed_response_wrapper( speech.transcribe, ) @@ -359,10 +356,7 @@ class AsyncSpeechResourceWithStreamingResponse: def __init__(self, speech: AsyncSpeechResource) -> None: self._speech = speech - self.generate = async_to_custom_streamed_response_wrapper( - speech.generate, - AsyncStreamedBinaryAPIResponse - ) + self.generate = async_to_custom_streamed_response_wrapper(speech.generate, AsyncStreamedBinaryAPIResponse) self.transcribe = async_to_streamed_response_wrapper( speech.transcribe, ) diff --git a/tests/test_models.py b/tests/test_models.py index 81c0437..74b79a2 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,7 +1,7 @@ import json from typing import Any, Dict, List, Union, Optional, cast from datetime import datetime, timezone -from typing_extensions import Literal, Annotated +from typing_extensions import Literal, Annotated, TypeAliasType import pytest import pydantic @@ -824,6 +824,7 @@ class B(BaseModel): # we hit the cache assert UnionType.__discriminator__ is discriminator + @pytest.mark.skipif(not PYDANTIC_V2, reason="TypeAliasType is not supported in Pydantic v1") def test_type_alias_type() -> None: Alias = TypeAliasType("Alias", str) # pyright: ignore diff --git a/tests/test_transform.py b/tests/test_transform.py index 20af831..4e904af 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -442,7 +442,7 @@ async def test_transform_skipping(use_async: bool) -> None: assert await transform(data, List[int], use_async) is data # iterables of ints are converted to a list - data = iter([1, 2, 3]) + data = iter([1, 2, 3]) # type: ignore assert await transform(data, Iterable[int], use_async) == [1, 2, 3]