Skip to content

Commit

Permalink
Support reserved word resource properties (#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
anniel-stripe authored Dec 18, 2023
1 parent d2b8ed1 commit 3a34544
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions stripe/_stripe_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ def __getattr__(self, k):
raise AttributeError(k)

try:
if k in self._field_remappings:
k = self._field_remappings[k]
return self[k]
except KeyError as err:
raise AttributeError(*err.args)
Expand Down Expand Up @@ -530,6 +532,8 @@ def __deepcopy__(self, memo: Dict[int, Any]) -> "StripeObject":

return copied

_field_remappings: ClassVar[Dict[str, str]] = {}

_inner_class_types: ClassVar[Dict[str, Type["StripeObject"]]] = {}
_inner_class_dicts: ClassVar[List[str]] = []

Expand Down
7 changes: 7 additions & 0 deletions tests/test_stripe_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,10 @@ def serialize(self, previous):
)

assert obj.serialize(None) == {"nested": ""}

def test_field_name_remapping(self):
class Foo(stripe.stripe_object.StripeObject):
_field_remappings = {"getter_name": "data_name"}

obj = Foo.construct_from({"data_name": "foo"}, "mykey")
assert obj.getter_name == "foo"

0 comments on commit 3a34544

Please sign in to comment.