8000 Types: Polymorphic groups by richardm-stripe · Pull Request #1080 · stripe/stripe-python · GitHub
[go: up one dir, main page]

Skip to content

Types: Polymorphic groups #1080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions stripe/api_resources/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from stripe.api_resources.list_object import ListObject
from stripe.request_options import RequestOptions
from stripe.stripe_object import StripeObject
from typing import Any, Dict, List, Optional, cast
from typing import Dict, List, Optional, Union, cast
from typing_extensions import (
Literal,
NotRequired,
Expand All @@ -22,6 +22,8 @@
from urllib.parse import quote_plus

if TYPE_CHECKING:
from stripe.api_resources.bank_account import BankAccount
from stripe.api_resources.card import Card
from stripe.api_resources.person import Person


Expand Down Expand Up @@ -977,7 +979,7 @@ class ListPersonsParamsRelationship(TypedDict):
default_currency: Optional[str]
details_submitted: Optional[bool]
email: Optional[str]
external_accounts: Optional[ListObject[Any]]
external_accounts: Optional[ListObject[Union["BankAccount", "Card"]]]
future_requirements: Optional[StripeObject]
id: str
individual: Optional["Person"]
Expand Down
53 changes: 51 additions & 2 deletions stripe/api_resources/balance_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from stripe.api_resources.list_object import ListObject
from stripe.request_options import RequestOptions
from stripe.stripe_object import StripeObject
from typing import Any, List, Optional
from typing import List, Optional, Union
from typing_extensions import (
Literal,
NotRequired,
Expand All @@ -14,6 +14,33 @@
TYPE_CHECKING,
)

if TYPE_CHECKING:
from stripe.api_resources.application_fee import ApplicationFee
from stripe.api_resources.application_fee_refund import (
ApplicationFeeRefund,
)
from stripe.api_resources.charge import Charge
from stripe.api_resources.connect_collection_transfer import (
ConnectCollectionTransfer,
)
from stripe.api_resources.customer_cash_balance_transaction import (
CustomerCashBalanceTransaction,
)
from stripe.api_resources.dispute import Dispute as DisputeResource
from stripe.api_resources.issuing.authorization import Authorization
from stripe.api_resources.issuing.dispute import (
Dispute as IssuingDisputeResource,
)
from stripe.api_resources.issuing.transaction import Transaction
from stripe.api_resources.payout import Payout
from stripe.api_resources.platform_tax_fee import PlatformTaxFee
from stripe.api_resources.refund import Refund
from stripe.api_resources.reserve_transaction import ReserveTransaction
from stripe.api_resources.reversal import Reversal
from stripe.api_resources.tax_deducted_at_source import TaxDeductedAtSource
from stripe.api_resources.topup import Topup
from stripe.api_resources.transfer import Transfer


class BalanceTransaction(ListableAPIResource["BalanceTransaction"]):
"""
Expand Down Expand Up @@ -60,7 +87,29 @@ class RetrieveParams(RequestOptions):
net: int
object: Literal["balance_transaction"]
reporting_category: str
source: Optional[ExpandableField[Any]]
source: Optional[
ExpandableField[
Union[
"ApplicationFee",
"Charge",
"ConnectCollectionTransfer",
"CustomerCashBalanceTransaction",
"DisputeResource",
"ApplicationFeeRefund",
"Authorization",
"IssuingDisputeResource",
"Transaction",
"Payout",
"PlatformTaxFee",
"Refund",
"ReserveTransaction",
"TaxDeductedAtSource",
"Topup",
"Transfer",
"Reversal",
]
]
]
status: str
type: Literal[
"adjustment",
Expand Down
13 changes: 9 additions & 4 deletions stripe/api_resources/bank_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
from stripe.api_resources.expandable_field import ExpandableField
from stripe.request_options import RequestOptions
from stripe.stripe_object import StripeObject
from typing import Any, Dict, List, Optional, cast
from typing import Dict, List, Optional, Union, cast
from typing_extensions import Literal, Unpack, TYPE_CHECKING
from urllib.parse import quote_plus

if TYPE_CHECKING:
from stripe.api_resources.card import Card


class BankAccount(
DeletableAPIResource["BankAccount"],
Expand Down Expand Up @@ -61,15 +64,17 @@ class DeleteParams(RequestOptions):
@classmethod
def _cls_delete(
cls, sid: str, **params: Unpack["BankAccount.DeleteParams"]
) -> Any:
) -> Union["BankAccount", "Card"]:
url = "%s/%s" % (cls.class_url(), quote_plus(sid))
return cast(
Any,
Union["BankAccount", "Card"],
cls._static_request("delete", url, params=params),
)

@util.class_method_variant("_cls_delete")
def delete(self, **params: Unpack["BankAccount.DeleteParams"]) -> Any:
def delete(
self, **params: Unpack["BankAccount.DeleteParams"]
) -> Union["BankAccount", "Card"]:
return self._request_and_refresh(
"delete",
self.instance_url(),
Expand Down
13 changes: 9 additions & 4 deletions stripe/api_resources/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
from stripe.api_resources.customer import Customer
from stripe.api_resources.expandable_field import ExpandableField
from stripe.request_options import RequestOptions
from typing import Any, Dict, List, Optional, cast
from typing import Dict, List, Optional, Union, cast
from typing_extensions import Literal, Unpack, TYPE_CHECKING
from urllib.parse import quote_plus

if TYPE_CHECKING:
from stripe.api_resources.bank_account import BankAccount


class Card(DeletableAPIResource["Card"], UpdateableAPIResource["Card"]):
"""
Expand Down Expand Up @@ -65,15 +68,17 @@ class DeleteParams(RequestOptions):
@classmethod
def _cls_delete(
cls, sid: str, **params: Unpack["Card.DeleteParams"]
) -> Any:
) -> Union["BankAccount", "Card"]:
url = "%s/%s" % (cls.class_url(), quote_plus(sid))
return cast(
Any,
Union["BankAccount", "Card"],
cls._static_request("delete", url, params=params),
)

@util.class_method_variant("_cls_delete")
def delete(self, **params: Unpack["Card.DeleteParams"]) -> Any:
def delete(
self, **params: Unpack["Card.DeleteParams"]
) -> Union["BankAccount", "Card"]:
return self._request_and_refresh(
"delete",
self.instance_url(),
Expand Down
7 changes: 5 additions & 2 deletions stripe/api_resources/charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from stripe.api_resources.search_result_object import SearchResultObject
from stripe.request_options import RequestOptions
from stripe.stripe_object import StripeObject
from typing import Any, Dict, List, Optional, Union, cast
from typing import Dict, List, Optional, Union, cast
from typing_extensions import (
Literal,
NotRequired,
Expand All @@ -27,11 +27,14 @@
from stripe.api_resources.application import Application
from stripe.api_resources.application_fee import ApplicationFee
from stripe.api_resources.balance_transaction import BalanceTransaction
from stripe.api_resources.bank_account import BankAccount
from stripe.api_resources.card import Card
from stripe.api_resources.customer import Customer
from stripe.api_resources.invoice import Invoice
from stripe.api_resources.payment_intent import PaymentIntent
from stripe.api_resources.refund import Refund
from stripe.api_resources.review import Review
from stripe.api_resources.source import Source
from stripe.api_resources.transfer import Transfer


Expand Down Expand Up @@ -207,7 +210,7 @@ class SearchParams(RequestOptions):
refunds: Optional[ListObject["Refund"]]
review: Optional[ExpandableField["Review"]]
shipping: Optional[StripeObject]
source: Optional[Any]
source: Optional[Union["Account", "BankAccount", "Card", "Source"]]
source_transfer: Optional[ExpandableField["Transfer"]]
statement_descriptor: Optional[str]
statement_descriptor_suffix: Optional[str]
Expand Down
14 changes: 11 additions & 3 deletions stripe/api_resources/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from stripe.api_resources.search_result_object import SearchResultObject
from stripe.request_options import RequestOptions
from stripe.stripe_object import StripeObject
from typing import Any, Dict, List, Optional, cast
from typing import Dict, List, Optional, Union, cast
from typing_extensions import (
Literal,
NotRequired,
Expand All @@ -27,8 +27,12 @@
from urllib.parse import quote_plus

if TYPE_CHECKING:
from stripe.api_resources.account import Account
from stripe.api_resources.bank_account import BankAccount
from stripe.api_resources.card import Card
from stripe.api_resources.cash_balance import CashBalance
from stripe.api_resources.discount import Discount
from stripe.api_resources.source import Source
from stripe.api_resources.subscription import Subscription
from stripe.api_resources.tax_id import TaxId
from stripe.api_resources.test_helpers.test_clock import TestClock
Expand Down Expand Up @@ -557,7 +561,9 @@ class ListTaxIdsParams(RequestOptions):
cash_balance: Optional["CashBalance"]
created: int
currency: Optional[str]
default_source: Optional[ExpandableField[Any]]
default_source: Optional[
ExpandableField[Union["Account", "BankAccount", "Card", "Source"]]
]
delinquent: Optional[bool]
description: Optional[str]
discount: Optional["Discount"]
Expand All @@ -574,7 +580,9 @@ class ListTaxIdsParams(RequestOptions):
phone: Optional[str]
preferred_locales: Optional[List[str]]
shipping: Optional[StripeObject]
sources: Optional[ListObject[Any]]
sources: Optional[
ListObject[Union["Account", "BankAccount", "Card", "Source"]]
]
subscriptions: Optional[ListObject["Subscription"]]
tax: Optional[StripeObject]
tax_exempt: Optional[Literal["exempt", "none", "reverse"]]
Expand Down
9 changes: 7 additions & 2 deletions stripe/api_resources/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from stripe.api_resources.search_result_object import SearchResultObject
from stripe.request_options import RequestOptions
from stripe.stripe_object import StripeObject
from typing import Any, Dict, List, Optional, cast
from typing import Dict, List, Optional, Union, cast
from typing_extensions import (
Literal,
NotRequired,
Expand All @@ -26,13 +26,16 @@
if TYPE_CHECKING:
from stripe.api_resources.account import Account
from stripe.api_resources.application import Application
from stripe.api_resources.bank_account import BankAccount
from stripe.api_resources.card import Card
from stripe.api_resources.charge import Charge
from stripe.api_resources.customer import Customer
from stripe.api_resources.discount import Discount
from stripe.api_resources.invoice_line_item import InvoiceLineItem
from stripe.api_resources.payment_intent import PaymentIntent
from stripe.api_resources.payment_method import PaymentMethod
from stripe.api_resources.quote import Quote
from stripe.api_resources.source import Source
from stripe.api_resources.subscription import Subscription
from stripe.api_resources.tax_id import TaxId
from stripe.api_resources.tax_rate import TaxRate
Expand Down Expand Up @@ -1188,7 +1191,9 @@ class SearchParams(RequestOptions):
customer_tax_exempt: Optional[Literal["exempt", "none", "reverse"]]
customer_tax_ids: Optional[List[StripeObject]]
default_payment_method: Optional[ExpandableField["PaymentMethod"]]
default_source: Optional[ExpandableField[Any]]
default_source: Optional[
ExpandableField[Union["Account", "BankAccount", "Card", "Source"]]
]
default_tax_rates: List["TaxRate"]
description: Optional[str]
discount: Optional["Discount"]
Expand Down
9 changes: 7 additions & 2 deletions stripe/api_resources/payment_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from stripe.api_resources.search_result_object import SearchResultObject
from stripe.request_options import RequestOptions
from stripe.stripe_object import StripeObject
from typing import Any, Dict, List, Optional, cast
from typing import Dict, List, Optional, Union, cast
from typing_extensions import (
Literal,
NotRequired,
Expand All @@ -25,11 +25,14 @@
if TYPE_CHECKING:
from stripe.api_resources.account import Account
from stripe.api_resources.application import Application
from stripe.api_resources.bank_account import BankAccount
from stripe.api_resources.card import Card
from stripe.api_resources.charge import Charge
from stripe.api_resources.customer import Customer
from stripe.api_resources.invoice import Invoice
from stripe.api_resources.payment_method import PaymentMethod
from stripe.api_resources.review import Review
from stripe.api_resources.source import Source


class PaymentIntent(
Expand Down Expand Up @@ -2485,7 +2488,9 @@ class SearchParams(RequestOptions):
review: Optional[ExpandableField["Review"]]
setup_future_usage: Optional[Literal["off_session", "on_session"]]
shipping: Optional[StripeObject]
source: Optional[ExpandableField[Any]]
source: Optional[
ExpandableField[Union["Account", "BankAccount", "Card", "Source"]]
]
statement_descriptor: Optional[str]
statement_descriptor_suffix: Optional[str]
status: Literal[
Expand Down
6 changes: 4 additions & 2 deletions stripe/api_resources/payout.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from stripe.api_resources.expandable_field import ExpandableField
from stripe.api_resources.list_object import ListObject
from stripe.request_options import RequestOptions
from typing import Any, Dict, List, Optional, cast
from typing import Dict, List, Optional, Union, cast
from typing_extensions import (
Literal,
NotRequired,
Expand All @@ -21,6 +21,8 @@

if TYPE_CHECKING:
from stripe.api_resources.balance_transaction import BalanceTransaction
from stripe.api_resources.bank_account import BankAccount
from stripe.api_resources.card import Card


class Payout(
Expand Down Expand Up @@ -98,7 +100,7 @@ class ReverseParams(RequestOptions):
created: int
currency: str
description: Optional[str]
destination: Optional[ExpandableField[Any]]
destination: Optional[ExpandableField[Union["BankAccount", "Card"]]]
failure_balance_transaction: Optional[
ExpandableField["BalanceTransaction"]
]
Expand Down
9 changes: 7 additions & 2 deletions stripe/api_resources/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from stripe.api_resources.search_result_object import SearchResultObject
from stripe.request_options import RequestOptions
from stripe.stripe_object import StripeObject
from typing import Any, Dict, List, Optional, cast
from typing import Dict, List, Optional, Union, cast
from typing_extensions import (
Literal,
NotRequired,
Expand All @@ -26,11 +26,14 @@
if TYPE_CHECKING:
from stripe.api_resources.account import Account
from stripe.api_resources.application import Application
from stripe.api_resources.bank_account import BankAccount
from stripe.api_resources.card import Card
from stripe.api_resources.customer import Customer
from stripe.api_resources.discount import Discount
from stripe.api_resources.invoice import Invoi 82FA ce
from stripe.api_resources.payment_method import PaymentMethod
from stripe.api_resources.setup_intent import SetupIntent
from stripe.api_resources.source import Source
from stripe.api_resources.subscription_item import SubscriptionItem
from stripe.api_resources.subscription_schedule import SubscriptionSchedule
from stripe.api_resources.tax_rate import TaxRate
Expand Down Expand Up @@ -653,7 +656,9 @@ class SearchParams(RequestOptions):
customer: ExpandableField["Customer"]
days_until_due: Optional[int]
default_payment_method: Optional[ExpandableField["PaymentMethod"]]
default_source: Optional[ExpandableField[Any]]
default_source: Optional[
ExpandableField[Union["Account", "BankAccount", "Card", "Source"]]
]
default_tax_rates: Optional[List["TaxRate"]]
description: Optional[str]
discount: Optional["Discount"]
Expand Down
Loading
0