From bdfcf59ed9c920ce521a47007f83d1add8516c9e Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Fri, 5 Jan 2024 23:07:48 +0000 Subject: [PATCH] chore(internal): loosen type var restrictions --- src/orb/_base_client.py | 41 +++++++++---------- src/orb/_response.py | 4 +- src/orb/_types.py | 17 +++++--- src/orb/pagination.py | 17 ++++---- src/orb/resources/coupons/coupons.py | 8 +--- src/orb/resources/coupons/subscriptions.py | 8 +--- src/orb/resources/credit_notes.py | 8 +--- .../customers/balance_transactions.py | 8 +--- src/orb/resources/customers/costs.py | 8 +--- .../resources/customers/credits/credits.py | 8 +--- src/orb/resources/customers/credits/ledger.py | 8 +--- src/orb/resources/customers/customers.py | 9 +--- src/orb/resources/customers/usage.py | 8 +--- src/orb/resources/events/backfills.py | 8 +--- src/orb/resources/events/events.py | 8 +--- src/orb/resources/invoice_line_items.py | 8 +--- src/orb/resources/invoices.py | 8 +--- src/orb/resources/items.py | 8 +--- src/orb/resources/metrics.py | 8 +--- src/orb/resources/plans/external_plan_id.py | 8 +--- src/orb/resources/plans/plans.py | 8 +--- src/orb/resources/prices/external_price_id.py | 8 +--- src/orb/resources/prices/prices.py | 8 +--- src/orb/resources/subscriptions.py | 8 +--- src/orb/resources/top_level.py | 8 +--- 25 files changed, 62 insertions(+), 186 deletions(-) diff --git a/src/orb/_base_client.py b/src/orb/_base_client.py index 53a53d80..97c6bef9 100644 --- a/src/orb/_base_client.py +++ b/src/orb/_base_client.py @@ -48,7 +48,6 @@ Body, Omit, Query, - ModelT, Headers, Timeout, NotGiven, @@ -61,7 +60,6 @@ HttpxSendArgs, AsyncTransport, RequestOptions, - UnknownResponse, ModelBuilderProtocol, BinaryResponseContent, ) @@ -142,7 +140,7 @@ def __init__( self.params = params -class BasePage(GenericModel, Generic[ModelT]): +class BasePage(GenericModel, Generic[_T]): """ Defines the core interface for pagination. @@ -155,7 +153,7 @@ class BasePage(GenericModel, Generic[ModelT]): """ _options: FinalRequestOptions = PrivateAttr() - _model: Type[ModelT] = PrivateAttr() + _model: Type[_T] = PrivateAttr() def has_next_page(self) -> bool: items = self._get_page_items() @@ -166,7 +164,7 @@ def has_next_page(self) -> bool: def next_page_info(self) -> Optional[PageInfo]: ... - def _get_page_items(self) -> Iterable[ModelT]: # type: ignore[empty-body] + def _get_page_items(self) -> Iterable[_T]: # type: ignore[empty-body] ... def _params_from_url(self, url: URL) -> httpx.QueryParams: @@ -191,13 +189,13 @@ def _info_to_options(self, info: PageInfo) -> FinalRequestOptions: raise ValueError("Unexpected PageInfo state") -class BaseSyncPage(BasePage[ModelT], Generic[ModelT]): +class BaseSyncPage(BasePage[_T], Generic[_T]): _client: SyncAPIClient = pydantic.PrivateAttr() def _set_private_attributes( self, client: SyncAPIClient, - model: Type[ModelT], + model: Type[_T], options: FinalRequestOptions, ) -> None: self._model = model @@ -212,7 +210,7 @@ def _set_private_attributes( # methods should continue to work as expected as there is an alternative method # to cast a model to a dictionary, model.dict(), which is used internally # by pydantic. - def __iter__(self) -> Iterator[ModelT]: # type: ignore + def __iter__(self) -> Iterator[_T]: # type: ignore for page in self.iter_pages(): for item in page._get_page_items(): yield item @@ -237,13 +235,13 @@ def get_next_page(self: SyncPageT) -> SyncPageT: return self._client._request_api_list(self._model, page=self.__class__, options=options) -class AsyncPaginator(Generic[ModelT, AsyncPageT]): +class AsyncPaginator(Generic[_T, AsyncPageT]): def __init__( self, client: AsyncAPIClient, options: FinalRequestOptions, page_cls: Type[AsyncPageT], - model: Type[ModelT], + model: Type[_T], ) -> None: self._model = model self._client = client @@ -266,7 +264,7 @@ def _parser(resp: AsyncPageT) -> AsyncPageT: return await self._client.request(self._page_cls, self._options) - async def __aiter__(self) -> AsyncIterator[ModelT]: + async def __aiter__(self) -> AsyncIterator[_T]: # https://github.com/microsoft/pyright/issues/3464 page = cast( AsyncPageT, @@ -276,12 +274,12 @@ async def __aiter__(self) -> AsyncIterator[ModelT]: yield item -class BaseAsyncPage(BasePage[ModelT], Generic[ModelT]): +class BaseAsyncPage(BasePage[_T], Generic[_T]): _client: AsyncAPIClient = pydantic.PrivateAttr() def _set_private_attributes( self, - model: Type[ModelT], + model: Type[_T], client: AsyncAPIClient, options: FinalRequestOptions, ) -> None: @@ -289,7 +287,7 @@ def _set_private_attributes( self._client = client self._options = options - async def __aiter__(self) -> AsyncIterator[ModelT]: + async def __aiter__(self) -> AsyncIterator[_T]: async for page in self.iter_pages(): for item in page._get_page_items(): yield item @@ -528,7 +526,7 @@ def _process_response_data( if data is None: return cast(ResponseT, None) - if cast_to is UnknownResponse: + if cast_to is object: return cast(ResponseT, data) try: @@ -970,7 +968,7 @@ def _retry_request( def _request_api_list( self, - model: Type[ModelT], + model: Type[object], page: Type[SyncPageT], options: FinalRequestOptions, ) -> SyncPageT: @@ -1132,7 +1130,7 @@ def get_api_list( self, path: str, *, - model: Type[ModelT], + model: Type[object], page: Type[SyncPageT], body: Body | None = None, options: RequestOptions = {}, @@ -1434,10 +1432,10 @@ async def _retry_request( def _request_api_list( self, - model: Type[ModelT], + model: Type[_T], page: Type[AsyncPageT], options: FinalRequestOptions, - ) -> AsyncPaginator[ModelT, AsyncPageT]: + ) -> AsyncPaginator[_T, AsyncPageT]: return AsyncPaginator(client=self, options=options, page_cls=page, model=model) @overload @@ -1584,13 +1582,12 @@ def get_api_list( self, path: str, *, - # TODO: support paginating `str` - model: Type[ModelT], + model: Type[_T], page: Type[AsyncPageT], body: Body | None = None, options: RequestOptions = {}, method: str = "get", - ) -> AsyncPaginator[ModelT, AsyncPageT]: + ) -> AsyncPaginator[_T, AsyncPageT]: opts = FinalRequestOptions.construct(method=method, url=path, json_data=body, **options) return self._request_api_list(model, page, opts) diff --git a/src/orb/_response.py b/src/orb/_response.py index 9da45b45..cd323b8a 100644 --- a/src/orb/_response.py +++ b/src/orb/_response.py @@ -9,7 +9,7 @@ import httpx -from ._types import NoneType, UnknownResponse, BinaryResponseContent +from ._types import NoneType, BinaryResponseContent from ._utils import is_given, extract_type_var_from_base from ._models import BaseModel, is_basemodel from ._constants import RAW_RESPONSE_HEADER @@ -162,7 +162,7 @@ def _parse(self) -> R: # `ResponseT` TypeVar, however if that TypeVar is ever updated in the future, then # this function would become unsafe but a type checker would not report an error. if ( - cast_to is not UnknownResponse + cast_to is not object and not origin is list and not origin is dict and not origin is Union diff --git a/src/orb/_types.py b/src/orb/_types.py index cbfaf62a..9b733640 100644 --- a/src/orb/_types.py +++ b/src/orb/_types.py @@ -258,11 +258,6 @@ class RequestOptions(TypedDict, total=False): idempotency_key: str -# Sentinel class used when the response type is an object with an unknown schema -class UnknownResponse: - ... - - # Sentinel class used until PEP 0661 is accepted class NotGiven: """ @@ -339,7 +334,17 @@ def get(self, __key: str) -> str | None: ResponseT = TypeVar( "ResponseT", - bound="Union[str, None, BaseModel, List[Any], Dict[str, Any], Response, UnknownResponse, ModelBuilderProtocol, BinaryResponseContent]", + bound=Union[ + object, + str, + None, + "BaseModel", + List[Any], + Dict[str, Any], + Response, + ModelBuilderProtocol, + BinaryResponseContent, + ], ) StrBytesIntFloat = Union[str, bytes, int, float] diff --git a/src/orb/pagination.py b/src/orb/pagination.py index 6b2c305c..53c9e7f4 100644 --- a/src/orb/pagination.py +++ b/src/orb/pagination.py @@ -1,14 +1,15 @@ # File generated from our OpenAPI spec by Stainless. -from typing import List, Generic, Optional +from typing import List, Generic, TypeVar, Optional from typing_extensions import override -from ._types import ModelT from ._models import BaseModel from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage __all__ = ["PagePaginationMetadata", "SyncPage", "AsyncPage"] +_T = TypeVar("_T") + class PagePaginationMetadata(BaseModel): has_more: bool @@ -16,12 +17,12 @@ class PagePaginationMetadata(BaseModel): next_cursor: Optional[str] = None -class SyncPage(BaseSyncPage[ModelT], BasePage[ModelT], Generic[ModelT]): - data: List[ModelT] +class SyncPage(BaseSyncPage[_T], BasePage[_T], Generic[_T]): + data: List[_T] pagination_metadata: PagePaginationMetadata @override - def _get_page_items(self) -> List[ModelT]: + def _get_page_items(self) -> List[_T]: data = self.data if not data: return [] @@ -38,12 +39,12 @@ def next_page_info(self) -> Optional[PageInfo]: return PageInfo(params={"cursor": next_cursor}) -class AsyncPage(BaseAsyncPage[ModelT], BasePage[ModelT], Generic[ModelT]): - data: List[ModelT] +class AsyncPage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]): + data: List[_T] pagination_metadata: PagePaginationMetadata @override - def _get_page_items(self) -> List[ModelT]: + def _get_page_items(self) -> List[_T]: data = self.data if not data: return [] diff --git a/src/orb/resources/coupons/coupons.py b/src/orb/resources/coupons/coupons.py index 22c20850..8f2ec247 100644 --- a/src/orb/resources/coupons/coupons.py +++ b/src/orb/resources/coupons/coupons.py @@ -7,13 +7,7 @@ import httpx from ...types import Coupon, coupon_list_params, coupon_create_params -from ..._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven from ..._utils import maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/coupons/subscriptions.py b/src/orb/resources/coupons/subscriptions.py index 26d748cb..05575905 100644 --- a/src/orb/resources/coupons/subscriptions.py +++ b/src/orb/resources/coupons/subscriptions.py @@ -7,13 +7,7 @@ import httpx from ...types import Subscription -from ..._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven from ..._utils import maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/credit_notes.py b/src/orb/resources/credit_notes.py index 41b5c1ba..3404c6a0 100644 --- a/src/orb/resources/credit_notes.py +++ b/src/orb/resources/credit_notes.py @@ -7,13 +7,7 @@ import httpx from ..types import CreditNote, credit_note_list_params -from .._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven from .._utils import maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/customers/balance_transactions.py b/src/orb/resources/customers/balance_transactions.py index 772fac93..b8dcd52b 100644 --- a/src/orb/resources/customers/balance_transactions.py +++ b/src/orb/resources/customers/balance_transactions.py @@ -8,13 +8,7 @@ import httpx -from ..._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven from ..._utils import maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/customers/costs.py b/src/orb/resources/customers/costs.py index f6f9a156..37fc3df9 100644 --- a/src/orb/resources/customers/costs.py +++ b/src/orb/resources/customers/costs.py @@ -8,13 +8,7 @@ import httpx -from ..._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven from ..._utils import maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/customers/credits/credits.py b/src/orb/resources/customers/credits/credits.py index 5bda5d1b..77111dd4 100644 --- a/src/orb/resources/customers/credits/credits.py +++ b/src/orb/resources/customers/credits/credits.py @@ -7,13 +7,7 @@ import httpx from .ledger import Ledger, AsyncLedger, LedgerWithRawResponse, AsyncLedgerWithRawResponse -from ...._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven from ...._utils import maybe_transform from ...._compat import cached_property from ...._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/customers/credits/ledger.py b/src/orb/resources/customers/credits/ledger.py index ed2999ea..65235167 100644 --- a/src/orb/resources/customers/credits/ledger.py +++ b/src/orb/resources/customers/credits/ledger.py @@ -8,13 +8,7 @@ import httpx -from ...._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven from ...._utils import required_args, maybe_transform from ...._compat import cached_property from ...._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/customers/customers.py b/src/orb/resources/customers/customers.py index fa4e560b..b6a3d5ac 100644 --- a/src/orb/resources/customers/customers.py +++ b/src/orb/resources/customers/customers.py @@ -18,14 +18,7 @@ customer_update_by_external_id_params, ) from .credits import Credits, AsyncCredits, CreditsWithRawResponse, AsyncCreditsWithRawResponse -from ..._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NoneType, - NotGiven, -) +from ..._types import NOT_GIVEN, Body, Query, Headers, NoneType, NotGiven from ..._utils import maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/customers/usage.py b/src/orb/resources/customers/usage.py index c8a45485..308a381e 100644 --- a/src/orb/resources/customers/usage.py +++ b/src/orb/resources/customers/usage.py @@ -7,13 +7,7 @@ import httpx -from ..._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven from ..._utils import maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/events/backfills.py b/src/orb/resources/events/backfills.py index 09fdb29e..0d8d03f6 100644 --- a/src/orb/resources/events/backfills.py +++ b/src/orb/resources/events/backfills.py @@ -7,13 +7,7 @@ import httpx -from ..._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven from ..._utils import maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/events/events.py b/src/orb/resources/events/events.py index 912eaf71..606ac62d 100644 --- a/src/orb/resources/events/events.py +++ b/src/orb/resources/events/events.py @@ -16,13 +16,7 @@ event_search_params, event_update_params, ) -from ..._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven from ..._utils import maybe_transform from ..._compat import cached_property from .backfills import Backfills, AsyncBackfills, BackfillsWithRawResponse, AsyncBackfillsWithRawResponse diff --git a/src/orb/resources/invoice_line_items.py b/src/orb/resources/invoice_line_items.py index 13d9984d..fc1560ad 100644 --- a/src/orb/resources/invoice_line_items.py +++ b/src/orb/resources/invoice_line_items.py @@ -8,13 +8,7 @@ import httpx from ..types import InvoiceLineItemCreateResponse, invoice_line_item_create_params -from .._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven from .._utils import maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/invoices.py b/src/orb/resources/invoices.py index bf915d2a..3b922a7c 100644 --- a/src/orb/resources/invoices.py +++ b/src/orb/resources/invoices.py @@ -16,13 +16,7 @@ invoice_mark_paid_params, invoice_fetch_upcoming_params, ) -from .._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven from .._utils import maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/items.py b/src/orb/resources/items.py index 5ab489bd..c18d002a 100644 --- a/src/orb/resources/items.py +++ b/src/orb/resources/items.py @@ -7,13 +7,7 @@ import httpx from ..types import Item, item_list_params, item_create_params -from .._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven from .._utils import maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/metrics.py b/src/orb/resources/metrics.py index 6c16ddac..3d215134 100644 --- a/src/orb/resources/metrics.py +++ b/src/orb/resources/metrics.py @@ -14,13 +14,7 @@ metric_list_params, metric_create_params, ) -from .._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven from .._utils import maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/plans/external_plan_id.py b/src/orb/resources/plans/external_plan_id.py index 9cf5a4e3..6fd204f4 100644 --- a/src/orb/resources/plans/external_plan_id.py +++ b/src/orb/resources/plans/external_plan_id.py @@ -7,13 +7,7 @@ import httpx from ...types import Plan -from ..._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven from ..._utils import maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/plans/plans.py b/src/orb/resources/plans/plans.py index 00187ad7..ad9f334e 100644 --- a/src/orb/resources/plans/plans.py +++ b/src/orb/resources/plans/plans.py @@ -9,13 +9,7 @@ import httpx from ...types import Plan, plan_list_params, plan_create_params, plan_update_params -from ..._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven from ..._utils import maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/prices/external_price_id.py b/src/orb/resources/prices/external_price_id.py index 6e9ec361..3cb11015 100644 --- a/src/orb/resources/prices/external_price_id.py +++ b/src/orb/resources/prices/external_price_id.py @@ -7,13 +7,7 @@ import httpx from ...types import Price -from ..._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper diff --git a/src/orb/resources/prices/prices.py b/src/orb/resources/prices/prices.py index aa732d07..f359402e 100644 --- a/src/orb/resources/prices/prices.py +++ b/src/orb/resources/prices/prices.py @@ -8,13 +8,7 @@ import httpx from ...types import Price, price_list_params, price_create_params -from ..._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven from ..._utils import required_args, maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/subscriptions.py b/src/orb/resources/subscriptions.py index a106e328..41495bfb 100644 --- a/src/orb/resources/subscriptions.py +++ b/src/orb/resources/subscriptions.py @@ -25,13 +25,7 @@ subscription_update_fixed_fee_quantity_params, subscription_unschedule_fixed_fee_quantity_updates_params, ) -from .._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven from .._utils import maybe_transform from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource diff --git a/src/orb/resources/top_level.py b/src/orb/resources/top_level.py index 41ae28cc..6d96d538 100644 --- a/src/orb/resources/top_level.py +++ b/src/orb/resources/top_level.py @@ -5,13 +5,7 @@ import httpx from ..types import TopLevelPingResponse -from .._types import ( - NOT_GIVEN, - Body, - Query, - Headers, - NotGiven, -) +from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven from .._compat import cached_property from .._resource import SyncAPIResource, AsyncAPIResource from .._response import to_raw_response_wrapper, async_to_raw_response_wrapper