Skip to content

Commit

Permalink
Fix __repr__ of Empty Struct (#259)
Browse files Browse the repository at this point in the history
This change fixes a bug where the empty Ion Struct was being
represented with only a closing brace.

After change:
```
>>> simpleion.loads('{}')
{}
>>> simpleion.loads('{"a":1}')
{'a': 1}
```

gh issue: #257
  • Loading branch information
rmarrowstone committed Apr 4, 2023
1 parent b08b9a7 commit 3c62e05
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions amazon/ion/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from collections import OrderedDict
except:
from collections import MutableMapping, MutableSequence, OrderedDict

from datetime import datetime, timedelta, tzinfo
from decimal import Decimal, ROUND_FLOOR, Context, Inexact
from math import isnan
Expand Down Expand Up @@ -635,10 +635,7 @@ def __str__(self):
return repr(self)

def __repr__(self):
str_repr = '{'
for key, value in self.items():
str_repr += '%r: %r, ' % (key, value)
return str_repr[:len(str_repr) - 2] + '}'
return '{%s}' % ', '.join(['%r: %r' % (k, v) for k, v in self.items()])

def add_item(self, key, value):
if key in self.__store:
Expand Down

0 comments on commit 3c62e05

Please sign in to comment.