Skip to content

Commit

Permalink
Merge branch 'master' into latest-codegen-master
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-stripe committed May 9, 2024
2 parents 8d81b2a + 71cf69e commit 4992d17
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 85 deletions.
33 changes: 0 additions & 33 deletions stripe/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,36 +433,3 @@ def _wrapper(*args, **kwargs):
return class_method(*args, **kwargs)

return _wrapper


def stripe_deprecate_param_inner(params: Mapping[str, Any], parts: List[str]):
cur = params
for i, part in enumerate(parts[:-1]):
if type(cur[part]) is list:
for item in cur[part]:
new_i = i + 1
stripe_deprecate_param_inner(item, parts[new_i:])
if part not in cur:
return

cur = cur[part]

deprecated_param = parts[-1]
if deprecated_param in cur:
warnings.warn(
f"The {deprecated_param} parameter is deprecated and will be removed in a future version. "
"Please refer to the changelog for more information.",
DeprecationWarning,
stacklevel=2,
)


def stripe_deprecate_parameter(key):
def stripe_deprecate_param_decorator(original_function):
def stripe_deprecate_param(params, *args, **kwargs):
stripe_deprecate_param_inner(params, key.split("."))
return original_function(params=params, *args, **kwargs)

return stripe_deprecate_param

return stripe_deprecate_param_decorator
52 changes: 0 additions & 52 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import stripe
from stripe import util
import pytest
import warnings

LogTestCase = namedtuple("LogTestCase", "env flag should_output")
FmtTestCase = namedtuple("FmtTestCase", "props expected")
Expand Down Expand Up @@ -152,53 +150,3 @@ def test_convert_to_stripe_object_and_back(self):
def test_sanitize_id(self):
sanitized_id = util.sanitize_id("cu %x 123")
assert sanitized_id == "cu++%25x+123"

def test_stripe_deprecate_parameter(self):
@util.stripe_deprecate_parameter("foo")
def to_be_decorated(**params):
pass

with warnings.catch_warnings():
warnings.simplefilter("error")
to_be_decorated(params={})

# assert that warnings.warn was called appropriately
with pytest.warns(DeprecationWarning):
to_be_decorated(params={"foo": True})

with warnings.catch_warnings():
warnings.simplefilter("error")
to_be_decorated(params={})

@util.stripe_deprecate_parameter("bar")
def to_be_decorated_non_existant_key(**params):
pass

with warnings.catch_warnings():
warnings.simplefilter("error")
to_be_decorated_non_existant_key(params={"foo": True})

@util.stripe_deprecate_parameter("")
def to_be_decorated_empty_key(**params):
pass

with warnings.catch_warnings():
warnings.simplefilter("error")
to_be_decorated_empty_key(params={"foo": True})

def test_stripe_deprecate_param_nested(self):
@util.stripe_deprecate_parameter("foo.bar")
def to_be_decorated_foo_bar(**params):
pass

with pytest.warns(DeprecationWarning):
to_be_decorated_foo_bar(params={"foo": {"bar": True}})

@util.stripe_deprecate_parameter("custom_fields.name")
def to_be_decorated_custom_fields_name(**params):
pass

with pytest.warns(DeprecationWarning):
to_be_decorated_custom_fields_name(
params={"custom_fields": [{"name": "blah"}]}
)

0 comments on commit 4992d17

Please sign in to comment.