Skip to content

Commit

Permalink
Types: annotate resource properties (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe authored Sep 1, 2023
1 parent 8506690 commit 6044d9f
Show file tree
Hide file tree
Showing 118 changed files with 2,438 additions and 23 deletions.
2 changes: 2 additions & 0 deletions stripe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
# API resources
from stripe.api_resources import * # pyright: ignore # noqa

from stripe.api_resources import abstract # pyright: ignore # noqa

# OAuth
from stripe.oauth import OAuth # noqa

Expand Down
11 changes: 11 additions & 0 deletions stripe/api_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from stripe.api_resources.account_link import AccountLink
from stripe.api_resources.account_session import AccountSession
from stripe.api_resources.apple_pay_domain import ApplePayDomain
from stripe.api_resources.application import Application
from stripe.api_resources.application_fee import ApplicationFee
from stripe.api_resources.application_fee_refund import ApplicationFeeRefund
from stripe.api_resources.balance import Balance
Expand All @@ -36,6 +37,9 @@
from stripe.api_resources.card import Card
from stripe.api_resources.cash_balance import CashBalance
from stripe.api_resources.charge import Charge
from stripe.api_resources.connect_collection_transfer import (
ConnectCollectionTransfer,
)
from stripe.api_resources.country_spec import CountrySpec
from stripe.api_resources.coupon import Coupon
from stripe.api_resources.credit_note import CreditNote
Expand All @@ -47,6 +51,7 @@
from stripe.api_resources.customer_cash_balance_transaction import (
CustomerCashBalanceTransaction,
)
from stripe.api_resources.discount import Discount
from stripe.api_resources.dispute import Dispute
from stripe.api_resources.ephemeral_key import EphemeralKey
from stripe.api_resources.event import Event
Expand All @@ -67,22 +72,28 @@
from stripe.api_resources.payout import Payout
from stripe.api_resources.person import Person
from stripe.api_resources.plan import Plan
from stripe.api_resources.platform_tax_fee import PlatformTaxFee
from stripe.api_resources.price import Price
from stripe.api_resources.product import Product
from stripe.api_resources.promotion_code import PromotionCode
from stripe.api_resources.quote import Quote
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.review import Review
from stripe.api_resources.setup_attempt import SetupAttempt
from stripe.api_resources.setup_intent import SetupIntent
from stripe.api_resources.shipping_rate import ShippingRate
from stripe.api_resources.source import Source
from stripe.api_resources.source_mandate_notification import (
SourceMandateNotification,
)
from stripe.api_resources.source_transaction import SourceTransaction
from stripe.api_resources.subscription import Subscription
from stripe.api_resources.subscription_item import SubscriptionItem
from stripe.api_resources.subscription_schedule import SubscriptionSchedule
from stripe.api_resources.tax_code import TaxCode
from stripe.api_resources.tax_deducted_at_source import TaxDeductedAtSource
from stripe.api_resources.tax_id import TaxId
from stripe.api_resources.tax_rate import TaxRate
from stripe.api_resources.token import Token
Expand Down
2 changes: 1 addition & 1 deletion stripe/api_resources/abstract/searchable_api_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from stripe.stripe_object import StripeObject


T = TypeVar("T", bound=StripeObject)
T = TypeVar("T", bound="StripeObject")


class SearchableAPIResource(APIResource[T]):
Expand Down
34 changes: 33 additions & 1 deletion stripe/api_resources/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@
from stripe.api_resources.abstract import ListableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
from stripe.api_resources.abstract import nested_resource_class_methods
from stripe.stripe_object import StripeObject
from typing import Any
from typing import Dict
from typing import Optional
from typing_extensions import Literal
from urllib.parse import quote_plus

from typing_extensions import TYPE_CHECKING

if TYPE_CHECKING:
from stripe.api_resources.person import Person


@nested_resource_class_methods(
"capability",
Expand Down Expand Up @@ -48,6 +58,28 @@ class Account(
"""

OBJECT_NAME = "account"
business_profile: Optional[StripeObject]
business_type: Optional[str]
capabilities: StripeObject
charges_enabled: bool
company: StripeObject
controller: StripeObject
country: str
created: str
default_currency: str
details_submitted: bool
email: Optional[str]
external_accounts: Any
future_requirements: StripeObject
id: str
individual: "Person"
metadata: Dict[str, str]
object: Literal["account"]
payouts_enabled: bool
requirements: StripeObject
settings: Optional[StripeObject]
tos_acceptance: StripeObject
type: str

@classmethod
def _cls_persons(
Expand Down Expand Up @@ -137,7 +169,7 @@ def instance_url(self):
return self._build_instance_url(self.get("id"))

def deauthorize(self, **params):
params["stripe_user_id"] = self.id # type: ignore
params["stripe_user_id"] = self.id
return oauth.OAuth.deauthorize(**params)

def serialize(self, previous):
Expand Down
5 changes: 5 additions & 0 deletions stripe/api_resources/account_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import absolute_import, division, print_function

from stripe.api_resources.abstract import CreateableAPIResource
from typing_extensions import Literal


class AccountLink(CreateableAPIResource["AccountLink"]):
Expand All @@ -14,3 +15,7 @@ class AccountLink(CreateableAPIResource["AccountLink"]):
"""

OBJECT_NAME = "account_link"
created: str
expires_at: str
object: Literal["account_link"]
url: str
8 changes: 8 additions & 0 deletions stripe/api_resources/account_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from __future__ import absolute_import, division, print_function

from stripe.api_resources.abstract import CreateableAPIResource
from stripe.stripe_object import StripeObject
from typing_extensions import Literal


class AccountSession(CreateableAPIResource["AccountSession"]):
Expand All @@ -17,3 +19,9 @@ class AccountSession(CreateableAPIResource["AccountSession"]):
"""

OBJECT_NAME = "account_session"
account: str
client_secret: str
components: StripeObject
expires_at: str
livemode: bool
object: Literal["account_session"]
6 changes: 6 additions & 0 deletions stripe/api_resources/apple_pay_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import DeletableAPIResource
from stripe.api_resources.abstract import ListableAPIResource
from typing_extensions import Literal


class ApplePayDomain(
Expand All @@ -13,6 +14,11 @@ class ApplePayDomain(
ListableAPIResource["ApplePayDomain"],
):
OBJECT_NAME = "apple_pay_domain"
created: str
domain_name: str
id: str
livemode: bool
object: Literal["apple_pay_domain"]

@classmethod
def class_url(cls):
Expand Down
14 changes: 14 additions & 0 deletions stripe/api_resources/application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from __future__ import absolute_import, division, print_function

from stripe.stripe_object import StripeObject
from typing import Optional
from typing_extensions import Literal


class Application(StripeObject):
OBJECT_NAME = "application"
id: str
name: Optional[str]
object: Literal["application"]
17 changes: 17 additions & 0 deletions stripe/api_resources/application_fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from stripe import util
from stripe.api_resources.abstract import ListableAPIResource
from stripe.api_resources.abstract import nested_resource_class_methods
from typing import Any
from typing import Optional
from typing_extensions import Literal


@nested_resource_class_methods(
Expand All @@ -13,6 +16,20 @@
)
class ApplicationFee(ListableAPIResource["ApplicationFee"]):
OBJECT_NAME = "application_fee"
account: Any
amount: int
amount_refunded: int
application: Any
balance_transaction: Optional[Any]
charge: Any
created: str
currency: str
id: str
livemode: bool
object: Literal["application_fee"]
originating_transaction: Optional[Any]
refunded: bool
refunds: Any

@classmethod
def _cls_refund(
Expand Down
14 changes: 13 additions & 1 deletion stripe/api_resources/application_fee_refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

from stripe.api_resources import ApplicationFee
from stripe.api_resources.abstract import UpdateableAPIResource
from typing import Any
from typing import Dict
from typing import Optional
from typing_extensions import Literal
from urllib.parse import quote_plus


Expand All @@ -17,6 +21,14 @@ class ApplicationFeeRefund(UpdateableAPIResource["ApplicationFeeRefund"]):
"""

OBJECT_NAME = "fee_refund"
amount: int
balance_transaction: Optional[Any]
created: str
currency: str
fee: Any
id: str
metadata: Optional[Dict[str, str]]
object: Literal["fee_refund"]

@classmethod
def _build_instance_url(cls, fee, sid):
Expand All @@ -31,7 +43,7 @@ def modify(cls, fee, sid, **params):
return cls._static_request("post", url, params=params)

def instance_url(self):
return self._build_instance_url(self.fee, self.id) # type: ignore
return self._build_instance_url(self.fee, self.id)

@classmethod
def retrieve(cls, id, api_key=None, **params):
Expand Down
12 changes: 12 additions & 0 deletions stripe/api_resources/apps/secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource
from stripe.stripe_object import StripeObject
from typing import Optional
from typing_extensions import Literal


class Secret(CreateableAPIResource["Secret"], ListableAPIResource["Secret"]):
Expand All @@ -20,6 +23,15 @@ class Secret(CreateableAPIResource["Secret"], ListableAPIResource["Secret"]):
"""

OBJECT_NAME = "apps.secret"
created: str
deleted: bool
expires_at: Optional[str]
id: str
livemode: bool
name: str
object: Literal["apps.secret"]
payload: Optional[str]
scope: StripeObject

@classmethod
def delete_where(
Expand Down
10 changes: 10 additions & 0 deletions stripe/api_resources/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from __future__ import absolute_import, division, print_function

from stripe.api_resources.abstract import SingletonAPIResource
from stripe.stripe_object import StripeObject
from typing import List
from typing_extensions import Literal


class Balance(SingletonAPIResource["Balance"]):
Expand All @@ -21,6 +24,13 @@ class Balance(SingletonAPIResource["Balance"]):
"""

OBJECT_NAME = "balance"
available: List[StripeObject]
connect_reserved: List[StripeObject]
instant_available: List[StripeObject]
issuing: StripeObject
livemode: bool
object: Literal["balance"]
pending: List[StripeObject]

@classmethod
def class_url(cls):
Expand Down
20 changes: 20 additions & 0 deletions stripe/api_resources/balance_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
from __future__ import absolute_import, division, print_function

from stripe.api_resources.abstract import ListableAPIResource
from stripe.stripe_object import StripeObject
from typing import Any
from typing import List
from typing import Optional
from typing_extensions import Literal


class BalanceTransaction(ListableAPIResource["BalanceTransaction"]):
Expand All @@ -14,3 +19,18 @@ class BalanceTransaction(ListableAPIResource["BalanceTransaction"]):
"""

OBJECT_NAME = "balance_transaction"
amount: int
available_on: str
created: str
currency: str
description: Optional[str]
exchange_rate: Optional[float]
fee: int
fee_details: List[StripeObject]
id: str
net: int
object: Literal["balance_transaction"]
reporting_category: str
source: Optional[Any]
status: str
type: str
Loading

0 comments on commit 6044d9f

Please # to comment.