Skip to content

Commit

Permalink
refactor: ensure types that come from arrays use singular names
Browse files Browse the repository at this point in the history
This is a breaking change
  • Loading branch information
stainless-bot committed Feb 10, 2023
1 parent e07d947 commit 36cf2fe
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 30 deletions.
24 changes: 22 additions & 2 deletions src/lithic/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
overload,
)
from functools import lru_cache
from typing_extensions import Literal
from typing_extensions import Literal, get_args, get_origin

import anyio
import httpx
Expand Down Expand Up @@ -409,13 +409,33 @@ def process_response(
cast_to: Type[ResponseT],
options: FinalRequestOptions,
response: httpx.Response,
_strict: bool = False,
) -> ResponseT:
if cast_to is NoneType:
return cast(ResponseT, None)

if cast_to == str:
return cast(ResponseT, response.text)

# TODO: try to handle Unions better…
if get_origin(cast_to) is Union:
members = get_args(cast_to)
for member in members:
try:
return cast(
ResponseT,
self.process_response(cast_to=member, options=options, response=response, _strict=True),
)
except:
continue
# If nobody matches exactly, try again loosely.
for member in members:
try:
return cast(ResponseT, self.process_response(cast_to=member, options=options, response=response))
except:
continue
raise ValueError(f"Response did not match any type in union {members}")

if issubclass(cast_to, httpx.Response):
# Because of the invariance of our ResponseT TypeVar, users can subclass httpx.Response
# and pass that class to our request functions. We cannot change the variance to be either
Expand Down Expand Up @@ -457,7 +477,7 @@ def process_response(
return cast(ResponseT, cast_to.build(response=response, data=data))

model_cls = cast(Type[BaseModel], cast_to)
if self._strict_response_validation:
if _strict or self._strict_response_validation:
return cast(ResponseT, model_cls(**data))

return cast(ResponseT, model_cls.construct(**data))
Expand Down
16 changes: 8 additions & 8 deletions src/lithic/resources/account_holders.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def create(
self,
*,
business_entity: account_holder_create_params.KYBBusinessEntity,
beneficial_owner_entities: List[account_holder_create_params.KYBBeneficialOwnerEntities],
beneficial_owner_individuals: List[account_holder_create_params.KYBBeneficialOwnerIndividuals],
beneficial_owner_entities: List[account_holder_create_params.KYBBeneficialOwnerEntity],
beneficial_owner_individuals: List[account_holder_create_params.KYBBeneficialOwnerIndividual],
control_person: account_holder_create_params.KYBControlPerson,
kyb_passed_timestamp: str | NotGiven = NOT_GIVEN,
nature_of_business: str,
Expand Down Expand Up @@ -219,8 +219,8 @@ def create(
self,
*,
business_entity: account_holder_create_params.KYBBusinessEntity | NotGiven = NOT_GIVEN,
beneficial_owner_entities: List[account_holder_create_params.KYBBeneficialOwnerEntities] | NotGiven = NOT_GIVEN,
beneficial_owner_individuals: List[account_holder_create_params.KYBBeneficialOwnerIndividuals]
beneficial_owner_entities: List[account_holder_create_params.KYBBeneficialOwnerEntity] | NotGiven = NOT_GIVEN,
beneficial_owner_individuals: List[account_holder_create_params.KYBBeneficialOwnerIndividual]
| NotGiven = NOT_GIVEN,
control_person: account_holder_create_params.KYBControlPerson | NotGiven = NOT_GIVEN,
kyb_passed_timestamp: str | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -619,8 +619,8 @@ async def create(
self,
*,
business_entity: account_holder_create_params.KYBBusinessEntity,
beneficial_owner_entities: List[account_holder_create_params.KYBBeneficialOwnerEntities],
beneficial_owner_individuals: List[account_holder_create_params.KYBBeneficialOwnerIndividuals],
beneficial_owner_entities: List[account_holder_create_params.KYBBeneficialOwnerEntity],
beneficial_owner_individuals: List[account_holder_create_params.KYBBeneficialOwnerIndividual],
control_person: account_holder_create_params.KYBControlPerson,
kyb_passed_timestamp: str | NotGiven = NOT_GIVEN,
nature_of_business: str,
Expand Down Expand Up @@ -809,8 +809,8 @@ async def create(
self,
*,
business_entity: account_holder_create_params.KYBBusinessEntity | NotGiven = NOT_GIVEN,
beneficial_owner_entities: List[account_holder_create_params.KYBBeneficialOwnerEntities] | NotGiven = NOT_GIVEN,
beneficial_owner_individuals: List[account_holder_create_params.KYBBeneficialOwnerIndividuals]
beneficial_owner_entities: List[account_holder_create_params.KYBBeneficialOwnerEntity] | NotGiven = NOT_GIVEN,
beneficial_owner_individuals: List[account_holder_create_params.KYBBeneficialOwnerIndividual]
| NotGiven = NOT_GIVEN,
control_person: account_holder_create_params.KYBControlPerson | NotGiven = NOT_GIVEN,
kyb_passed_timestamp: str | NotGiven = NOT_GIVEN,
Expand Down
2 changes: 1 addition & 1 deletion src/lithic/types/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from .._models import BaseModel

__all__ = ["SpendLimit", "Account"]
__all__ = ["Account", "SpendLimit"]


class SpendLimit(BaseModel):
Expand Down
18 changes: 9 additions & 9 deletions src/lithic/types/account_holder_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
from ..types import shared_params

__all__ = [
"AccountHolderCreateParams",
"KYB",
"KYBBusinessEntity",
"KYBBeneficialOwnerEntities",
"KYBBeneficialOwnerIndividuals",
"KYBBeneficialOwnerEntity",
"KYBBeneficialOwnerIndividual",
"KYBControlPerson",
"KYB",
"KYCIndividual",
"KYC",
"KYCIndividual",
"KYCExempt",
"AccountHolderCreateParams",
]


Expand Down Expand Up @@ -53,7 +53,7 @@ class KYBBusinessEntity(TypedDict, total=False):
"""Parent company name (if applicable)."""


class KYBBeneficialOwnerEntities(TypedDict, total=False):
class KYBBeneficialOwnerEntity(TypedDict, total=False):
address: Required[shared_params.Address]
"""
Business's physical address - PO boxes, UPS drops, and FedEx drops are not
Expand Down Expand Up @@ -86,7 +86,7 @@ class KYBBeneficialOwnerEntities(TypedDict, total=False):
"""Parent company name (if applicable)."""


class KYBBeneficialOwnerIndividuals(TypedDict, total=False):
class KYBBeneficialOwnerIndividual(TypedDict, total=False):
address: Required[shared_params.Address]
"""
Individual's current address - PO boxes, UPS drops, and FedEx drops are not
Expand Down Expand Up @@ -155,7 +155,7 @@ class KYBControlPerson(TypedDict, total=False):


class KYB(TypedDict, total=False):
beneficial_owner_entities: Required[List[KYBBeneficialOwnerEntities]]
beneficial_owner_entities: Required[List[KYBBeneficialOwnerEntity]]
"""List of all entities with >25% ownership in the company.
If no entity or individual owns >25% of the company, and the largest shareholder
Expand All @@ -166,7 +166,7 @@ class KYB(TypedDict, total=False):
must be populated. on entities that should be included.
"""

beneficial_owner_individuals: Required[List[KYBBeneficialOwnerIndividuals]]
beneficial_owner_individuals: Required[List[KYBBeneficialOwnerIndividual]]
"""List of all individuals with >25% ownership in the company.
If no entity or individual owns >25% of the company, and the largest shareholder
Expand Down
2 changes: 1 addition & 1 deletion src/lithic/types/account_holder_create_webhook_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .._models import BaseModel

__all__ = ["Data", "AccountHolderCreateWebhookResponse"]
__all__ = ["AccountHolderCreateWebhookResponse", "Data"]


class Data(BaseModel):
Expand Down
6 changes: 3 additions & 3 deletions src/lithic/types/account_holder_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

from .._models import BaseModel

__all__ = ["RequiredDocumentUploads", "AccountHolderDocument"]
__all__ = ["AccountHolderDocument", "RequiredDocumentUpload"]


class RequiredDocumentUploads(BaseModel):
class RequiredDocumentUpload(BaseModel):
image_type: Optional[Literal["back", "front"]]
"""Type of image to upload."""

Expand Down Expand Up @@ -44,7 +44,7 @@ class AccountHolderDocument(BaseModel):
document_type: Optional[Literal["commercial_license", "drivers_license", "passport", "passport_card", "visa"]]
"""Type of documentation to be submitted for verification."""

required_document_uploads: Optional[List[RequiredDocumentUploads]]
required_document_uploads: Optional[List[RequiredDocumentUpload]]

token: Optional[str]
"""Globally unique identifier for the document."""
2 changes: 1 addition & 1 deletion src/lithic/types/account_holder_resubmit_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ..types import shared_params

__all__ = ["Individual", "AccountHolderResubmitParams"]
__all__ = ["AccountHolderResubmitParams", "Individual"]


class Individual(TypedDict, total=False):
Expand Down
2 changes: 1 addition & 1 deletion src/lithic/types/account_update_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from typing_extensions import Literal, TypedDict

__all__ = ["VerificationAddress", "AccountUpdateParams"]
__all__ = ["AccountUpdateParams", "VerificationAddress"]


class VerificationAddress(TypedDict, total=False):
Expand Down
2 changes: 1 addition & 1 deletion src/lithic/types/funding_source_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Union
from typing_extensions import Literal, Required, TypedDict

__all__ = ["Bank", "Plaid", "FundingSourceCreateParams"]
__all__ = ["FundingSourceCreateParams", "Bank", "Plaid"]


class Bank(TypedDict, total=False):
Expand Down
6 changes: 3 additions & 3 deletions src/lithic/types/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..types import card
from .._models import BaseModel

__all__ = ["CardholderAuthentication", "Events", "Funding", "Merchant", "Transaction"]
__all__ = ["Transaction", "CardholderAuthentication", "Event", "Funding", "Merchant"]


class CardholderAuthentication(BaseModel):
Expand Down Expand Up @@ -115,7 +115,7 @@ class CardholderAuthentication(BaseModel):
"""


class Events(BaseModel):
class Event(BaseModel):
amount: int
"""Amount of the transaction event (in cents), including any acquirer fees."""

Expand Down Expand Up @@ -312,7 +312,7 @@ class Transaction(BaseModel):
created: Optional[str]
"""Date and time when the transaction first occurred. UTC time zone."""

events: Optional[List[Events]]
events: Optional[List[Event]]
"""A list of all events that have modified this transaction."""

funding: Optional[List[Funding]]
Expand Down

0 comments on commit 36cf2fe

Please sign in to comment.