Skip to content
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

Mark defunct and internal methods as deprecated #1101

Merged
merged 13 commits into from
Dec 12, 2023
9 changes: 8 additions & 1 deletion stripe/_api_requestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ def __init__(
self._default_proxy = proxy

@classmethod
@_util.deprecated(
"This method is internal to stripe-python and the public interface will be removed in a future stripe-python version"
)
def format_app_info(cls, info):
return cls._format_app_info(info)

@classmethod
def _format_app_info(cls, info):
str = info["name"]
if info["version"]:
str += "/%s" % (info["version"],)
Expand Down Expand Up @@ -230,7 +237,7 @@ def specific_oauth_error(self, rbody, rcode, resp, rheaders, error_code):
def request_headers(self, api_key, method):
user_agent = "Stripe/v1 PythonBindings/%s" % (_version.VERSION,)
if stripe.app_info:
user_agent += " " + self.format_app_info(stripe.app_info)
user_agent += " " + self._format_app_info(stripe.app_info)

ua = {
"bindings_version": _version.VERSION,
Expand Down
4 changes: 4 additions & 0 deletions stripe/_api_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
)
from stripe._api_requestor import APIRequestor
from stripe._stripe_object import StripeObject
from stripe import _util
from urllib.parse import quote_plus
from typing import (
Any,
Expand All @@ -28,6 +29,9 @@ class APIResource(StripeObject, Generic[T]):
OBJECT_NAME: ClassVar[str]

@classmethod
@_util.deprecated(
pakrym-stripe marked this conversation as resolved.
Show resolved Hide resolved
"This method is deprecated and will be removed in a future version of stripe-python. Child classes of APIResource should define their own `retrieve` and use APIResource._request directly."
)
def retrieve(cls, id, api_key=None, **params) -> T:
instance = cls(id, api_key, **params)
instance.refresh()
Expand Down
4 changes: 4 additions & 0 deletions stripe/_custom_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from urllib.parse import quote_plus


# TODO(major): 1704.
@_util.deprecated(
"the custom_method class decorator will be removed in a future version of stripe-python. Define custom methods directly and use StripeObject._static_request within."
)
def custom_method(
name: str,
http_verb: str,
Expand Down
10 changes: 9 additions & 1 deletion stripe/_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import stripe # noqa: IMP101
from stripe._error_object import ErrorObject

from stripe import _util
import warnings


class StripeError(Exception):
_message: Optional[str]
Expand Down Expand Up @@ -43,7 +46,9 @@ def __init__(
self.headers = headers or {}
self.code = code
self.request_id = self.headers.get("request-id", None)
self.error = self.construct_error_object()
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
self.error = self.construct_error_object()
pakrym-stripe marked this conversation as resolved.
Show resolved Hide resolved

def __str__(self):
msg = self._message or "<empty message>"
Expand All @@ -68,6 +73,9 @@ def __repr__(self):
self.request_id,
)

@_util.deprecated(
"For internal stripe-python use only. The public interface will be removed in a future version."
)
def construct_error_object(self) -> Optional[ErrorObject]:
if (
self.json_body is None
Expand Down
49 changes: 39 additions & 10 deletions stripe/_list_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
cast,
Mapping,
)
from stripe import _util
from stripe._stripe_object import StripeObject

from urllib.parse import quote_plus
import warnings

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

Expand All @@ -26,6 +28,9 @@ class ListObject(StripeObject, Generic[T]):
has_more: bool
url: str

@_util.deprecated(
"This will be removed in a future version of stripe-python. Please call the `list` method on the corresponding resource directly, instead of using `list` from the list object."
)
def list(
self,
api_key: Optional[str] = None,
Expand All @@ -50,6 +55,9 @@ def list(
),
)

@_util.deprecated(
"This will be removed in a future version of stripe-python. Please call the `create` method on the corresponding resource directly, instead of using `create` from the list object."
)
def create(
pakrym-stripe marked this conversation as resolved.
Show resolved Hide resolved
self,
api_key: Optional[str] = None,
Expand All @@ -76,6 +84,9 @@ def create(
),
)

@_util.deprecated(
"This will be removed in a future version of stripe-python. Please call the `retrieve` method on the corresponding resource directly, instead of using `retrieve` from the list object."
)
def retrieve(
self,
id: str,
Expand Down Expand Up @@ -148,11 +159,27 @@ def auto_paging_iter(self) -> Iterator[T]:
break

@classmethod
@_util.deprecated(
"This method is for internal stripe-python use only. The public interface will be removed in a future version."
)
def empty_list(
cls,
api_key: Optional[str] = None,
stripe_version: Optional[str] = None,
stripe_account: Optional[str] = None,
) -> Self:
return cls._empty_list(
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
)

@classmethod
def _empty_list(
cls,
api_key: Optional[str] = None,
stripe_version: Optional[str] = None,
stripe_account: Optional[str] = None,
) -> Self:
return cls.construct_from(
{"data": []},
Expand All @@ -174,7 +201,7 @@ def next_page(
**params: Mapping[str, Any]
) -> Self:
if not self.has_more:
return self.empty_list(
return self._empty_list(
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
Expand All @@ -190,13 +217,15 @@ def next_page(
params_with_filters.update({"starting_after": last_id})
params_with_filters.update(params)

result = self.list(
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
**params_with_filters,
)
return result
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=DeprecationWarning)
result = self.list( # pyright: ignore[reportDeprecated]
pakrym-stripe marked this conversation as resolved.
Show resolved Hide resolved
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
**params_with_filters,
)
return result

def previous_page(
self,
Expand All @@ -206,7 +235,7 @@ def previous_page(
**params: Mapping[str, Any]
) -> Self:
if not self.has_more:
return self.empty_list(
return self._empty_list(
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
Expand All @@ -222,7 +251,7 @@ def previous_page(
params_with_filters.update({"ending_before": first_id})
params_with_filters.update(params)

result = self.list(
result = self.list( # pyright: ignore[reportDeprecated]
richardm-stripe marked this conversation as resolved.
Show resolved Hide resolved
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
Expand Down
3 changes: 3 additions & 0 deletions stripe/_listable_api_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

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

# TODO(major): 1704 - remove this class and all internal usages. `.list` is already inlined into the resource classes.
# Although we should inline .auto_paging_iter into the resource classes as well.
pakrym-stripe marked this conversation as resolved.
Show resolved Hide resolved


class ListableAPIResource(APIResource[T]):
@classmethod
Expand Down
4 changes: 2 additions & 2 deletions stripe/_nested_resource_class_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from stripe._api_resource import APIResource


# TODO(major): Remove this. It is no longer used except for "nested_resource_url" and "nested_resource_request",
# which are unnecessary ande deprecated.
# TODO(major): 1704. Remove this. It is no longer used except for "nested_resource_url" and "nested_resource_request",
# which are unnecessary and deprecated and should also be removed.
def nested_resource_class_methods(
pakrym-stripe marked this conversation as resolved.
Show resolved Hide resolved
resource: str,
path: Optional[str] = None,
Expand Down
41 changes: 32 additions & 9 deletions stripe/_search_result_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
)

from stripe._stripe_object import StripeObject
from stripe import _util
import warnings

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

Expand All @@ -22,6 +24,9 @@ class SearchResultObject(StripeObject, Generic[T]):
has_more: bool
next_page: str

@_util.deprecated(
"This will be removed in a future version of stripe-python. Please call the `search` method on the corresponding resource directly, instead of the generic search on SearchResultObject."
)
def search(
self,
api_key: Optional[str] = None,
Expand Down Expand Up @@ -78,7 +83,7 @@ def auto_paging_iter(self) -> Iterator[T]:
break

@classmethod
def empty_search_result(
def _empty_search_result(
cls,
api_key: Optional[str] = None,
stripe_version: Optional[str] = None,
Expand All @@ -92,6 +97,22 @@ def empty_search_result(
last_response=None,
)

@classmethod
@_util.deprecated(
"For internal stripe-python use only. This will be removed in a future version."
)
def empty_search_result(
cls,
api_key: Optional[str] = None,
stripe_version: Optional[str] = None,
stripe_account: Optional[str] = None,
) -> Self:
return cls._empty_search_result(
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
)

@property
def is_empty(self) -> bool:
return not self.data
Expand All @@ -104,7 +125,7 @@ def next_search_result_page(
**params: Mapping[str, Any]
) -> Self:
if not self.has_more:
return self.empty_search_result(
return self._empty_search_result(
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
Expand All @@ -114,10 +135,12 @@ def next_search_result_page(
params_with_filters.update({"page": self.next_page})
params_with_filters.update(params)

result = self.search(
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
**params_with_filters,
)
return result
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
result = self.search( # pyright: ignore[reportDeprecated]
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
**params_with_filters,
)
return result
2 changes: 2 additions & 0 deletions stripe/_singleton_api_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

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

# TODO(major): 1704 - Inline into Tax.Settings and Balance, and remove this class.


class SingletonAPIResource(APIResource[T]):
@classmethod
Expand Down
Loading