Skip to content

Commit

Permalink
Centralize types
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Aug 22, 2023
1 parent c520c96 commit c43b1b7
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 18 deletions.
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
package_data={"stripe": ["data/ca-certificates.crt"]},
zip_safe=False,
install_requires=[
'typing_extensions <= 4.2.0; python_version < "3.7"',
'typing_extensions; python_version >= "3.7"',
'typing_extensions >= 4.7.1; python_version >= "3.7"',
'requests >= 2.20; python_version >= "3.0"',
],
python_requires=">=3.6",
Expand Down
2 changes: 1 addition & 1 deletion stripe/api_resources/abstract/api_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from stripe import api_requestor, error, util
from stripe.stripe_object import StripeObject
from urllib.parse import quote_plus
from typing_extensions import ClassVar
from typing import ClassVar


class APIResource(StripeObject):
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 @@ -3,7 +3,7 @@
from stripe.api_resources.abstract.api_resource import APIResource
from stripe.api_resources.search_result_object import SearchResultObject

from typing_extensions import cast
from stripe.typing import cast


class SearchableAPIResource(APIResource):
Expand Down
4 changes: 3 additions & 1 deletion stripe/api_resources/abstract/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from stripe import error
from urllib.parse import quote_plus

from typing_extensions import Any, ClassVar, TypeVar, Protocol
from typing import ClassVar

from stripe.typing import Any, TypeVar, Protocol

from stripe.api_resources.abstract.api_resource import APIResource

Expand Down
2 changes: 1 addition & 1 deletion stripe/api_resources/abstract/verify_mixin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import absolute_import, division, print_function
from typing_extensions import Optional, Protocol
from stripe.typing import Optional, Protocol

from stripe.stripe_object import StripeObject

Expand Down
2 changes: 1 addition & 1 deletion stripe/api_resources/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from stripe.api_resources.abstract import SearchableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
from stripe.api_resources.abstract import nested_resource_class_methods
from typing_extensions import Type
from stripe.typing import Type


@nested_resource_class_methods(
Expand Down
2 changes: 1 addition & 1 deletion stripe/api_resources/issuing/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
from typing_extensions import Type
from stripe.typing import Type


class Card(CreateableAPIResource, ListableAPIResource, UpdateableAPIResource):
Expand Down
2 changes: 1 addition & 1 deletion stripe/api_resources/refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
from typing_extensions import Type
from stripe.typing import Type


class Refund(
Expand Down
2 changes: 1 addition & 1 deletion stripe/api_resources/terminal/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from stripe.api_resources.abstract import DeletableAPIResource
from stripe.api_resources.abstract import ListableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
from typing_extensions import Type
from stripe.typing import Type


class Reader(
Expand Down
2 changes: 1 addition & 1 deletion stripe/api_resources/treasury/inbound_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from stripe.api_resources.abstract import APIResourceTestHelpers
from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource
from typing_extensions import Type
from stripe.typing import Type


class InboundTransfer(CreateableAPIResource, ListableAPIResource):
Expand Down
2 changes: 1 addition & 1 deletion stripe/api_resources/treasury/outbound_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from stripe.api_resources.abstract import APIResourceTestHelpers
from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource
from typing_extensions import Type
from stripe.typing import Type


class OutboundPayment(CreateableAPIResource, ListableAPIResource):
Expand Down
2 changes: 1 addition & 1 deletion stripe/api_resources/treasury/outbound_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from stripe.api_resources.abstract import APIResourceTestHelpers
from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import ListableAPIResource
from typing_extensions import Type
from stripe.typing import Type


class OutboundTransfer(CreateableAPIResource, ListableAPIResource):
Expand Down
2 changes: 1 addition & 1 deletion stripe/api_resources/treasury/received_credit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from stripe.api_resources.abstract import APIResourceTestHelpers
from stripe.api_resources.abstract import ListableAPIResource
from typing_extensions import Type
from stripe.typing import Type


class ReceivedCredit(ListableAPIResource):
Expand Down
2 changes: 1 addition & 1 deletion stripe/api_resources/treasury/received_debit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from stripe.api_resources.abstract import APIResourceTestHelpers
from stripe.api_resources.abstract import ListableAPIResource
from typing_extensions import Type
from stripe.typing import Type


class ReceivedDebit(ListableAPIResource):
Expand Down
2 changes: 1 addition & 1 deletion stripe/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from stripe import error, util
from stripe.request_metrics import RequestMetrics

from typing_extensions import NoReturn, Optional, cast, TypedDict, Dict
from stripe.typing import NoReturn, Optional, cast, TypedDict, Dict

# - Requests is the preferred HTTP library
# - Google App Engine has urlfetch
Expand Down
2 changes: 1 addition & 1 deletion stripe/stripe_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime
import json
from copy import deepcopy
from typing_extensions import TYPE_CHECKING
from stripe.typing import TYPE_CHECKING

import stripe
from stripe import api_requestor, util
Expand Down
29 changes: 29 additions & 0 deletions stripe/typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Centralized place for typing imports.

# The last version supported by Python 3.6 is typing_extensions 4.1.1. Unfortunately,
# typing_extensions didn't decide to re-export all of the types from typing until 4.7.0.
# TODO (major): if we drop support for Python 3.6, we can remove this file and just import
# everything from typing_extensions.

# Rules: don't depend on anything only in typing_extensions > 4.1.1. If we need something
# newer, we might be able to provide a better type for some users with a conditional import
# but we'll cross that bridge when we come to it.

# Note: we can't re-export *everything* here, unfortunately. Some special
# forms can't be aliased.
# > The following special forms cannot be re-exported: Final, ClassVar, and InitVar in pyright.
# (https://github.com/microsoft/pyright/discussions/4845#discussioncomment-5440032)

from typing import Optional as Optional
from typing import cast as cast
from typing import Dict as Dict
from typing import Any as Any
from typing import TypeVar as TypeVar
from typing import Union as Union
from typing_extensions import TYPE_CHECKING as TYPE_CHECKING
from typing_extensions import Literal as Literal
from typing_extensions import NoReturn as NoReturn
from typing_extensions import Protocol as Protocol
from typing_extensions import Type as Type
from typing_extensions import TypedDict as TypedDict
from typing_extensions import overload as overload
2 changes: 1 addition & 1 deletion stripe/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import stripe
from urllib.parse import parse_qsl, quote_plus

from typing_extensions import overload, Literal, Union
from stripe.typing import overload, Literal, Union

STRIPE_LOG = os.environ.get("STRIPE_LOG")

Expand Down

0 comments on commit c43b1b7

Please sign in to comment.