Skip to content

Commit

Permalink
Feedback from gdb
Browse files Browse the repository at this point in the history
  • Loading branch information
boucher committed Jan 28, 2012
1 parent 6167735 commit 01df3e1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions stripe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def convert_to_stripe_object(resp, api_key):
elif isinstance(resp, dict):
resp = resp.copy()
klass_name = resp.get('object')
klass = types.get(klass_name, StripeObject) if type(klass_name) == str else StripeObject
klass = types.get(klass_name, StripeObject) if isinstance(klass_name, basestring) else StripeObject
return klass.construct_from(resp, api_key)
else:
return resp
Expand Down Expand Up @@ -444,9 +444,10 @@ def __init__(self, id=None, api_key=None):
self.id = id

def __setattr__(self, k, v):
# TODO: may want to make ignored attributes immutable
self.__dict__[k] = v
self._values.add(k)
if k not in self._permanent_attributes:
self._unsaved_values.add(k)

def __getattr__(self, k):
try:
Expand Down Expand Up @@ -523,8 +524,8 @@ def refresh_from(self, values, api_key, partial=False):
self._unsaved_values.discard(k)

def __repr__(self):
type_string = (' %s' % str(self.get('object'))) if type(self.get('object', None)) == unicode else ""
id_string = (' id=%s' % str(self.get('id'))) if type(self.get('id', None)) == unicode else ""
type_string = (' %s' % str(self.get('object'))) if isinstance(self.get('object'), basestring) else ""
id_string = (' id=%s' % str(self.get('id'))) if if isinstance(self.get('id'), basestring) else ""

This comment has been minimized.

Copy link
@gdb

gdb Jan 28, 2012

Accidental double if

return '<%s%s%s at %s> JSON: %s' % (type(self).__name__, type_string, id_string, hex(id(self)), json.dumps(self.to_dict(), sort_keys=True, indent=2, cls=StripeObjectEncoder))

def __str__(self):
Expand All @@ -543,7 +544,8 @@ class StripeObjectEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, StripeObject):
return json.dumps(obj.to_dict(), cls=StripeObjectEncoder)
return json.JSONEncoder.default(self, obj)
else:
return json.JSONEncoder.default(self, obj)

class APIResource(StripeObject):
def _ident(self):
Expand Down

0 comments on commit 01df3e1

Please sign in to comment.