Skip to content

Commit

Permalink
Reduce noise in repr output
Browse files Browse the repository at this point in the history
  • Loading branch information
patrys committed Sep 12, 2012
1 parent e7753e4 commit 4df4bce
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -30,4 +30,4 @@ And being helpful::
>>> p += price(50)
>>> p += lineartax('1.23', '23% VAT')
>>> inspect_price(p)
"price(Decimal('1.99'), currency=None) + price(Decimal('50'), currency=None) + lineartax(Decimal('1.23'), name='23% VAT')"
"price('1.99', currency=None) + price('50', currency=None) + lineartax('1.23', name='23% VAT')"
8 changes: 4 additions & 4 deletions prices/__init__.py
Expand Up @@ -25,9 +25,9 @@ def __init__(self, net, gross=None, currency=None, previous=None,

def __repr__(self):
if self.net == self.gross:
return 'price(%r, currency=%r)' % (self.net, self.currency)
return 'price(%r, currency=%r)' % (str(self.net), self.currency)
return ('price(net=%r, gross=%r, currency=%r)' %
(self.net, self.gross, self.currency))
(str(self.net), str(self.gross), self.currency))

def __lt__(self, other):
if isinstance(other, price):
Expand Down Expand Up @@ -204,7 +204,7 @@ def __init__(self, multiplier, name=None):
self.name = name or self.name

def __repr__(self):
return 'lineartax(%r, name=%r)' % (self.multiplier, self.name)
return 'lineartax(%r, name=%r)' % (str(self.multiplier), self.name)

def __lt__(self, other):
if not isinstance(other, lineartax):
Expand All @@ -231,7 +231,7 @@ def format_inspect(data):
if op is operator.__mul__:
return '(%s) * %r' % (format_inspect(op1), op2)
if op == price.quantize:
return '(%s).quantize(%r)' % (format_inspect(op1), op2)
return '(%s).quantize(%r)' % (format_inspect(op1), str(op2))
return '%s + %s' % (format_inspect(op1), format_inspect(op2))
return repr(data)
return format_inspect(price_obj.inspect())
2 changes: 1 addition & 1 deletion prices/tests/test_prices.py
Expand Up @@ -53,7 +53,7 @@ def test_inspect(self):
p = ((self.ten_btc + self.twenty_btc) * 5 + tax).quantize('0.01')
self.assertEqual(
inspect_price(p),
"((price(Decimal('10'), currency='BTC') + price(Decimal('20'), currency='BTC')) * 5 + lineartax(Decimal('1.2345678'), name='Silly Tax')).quantize(Decimal('0.01'))")
"((price('10', currency='BTC') + price('20', currency='BTC')) * 5 + lineartax('1.2345678', name='Silly Tax')).quantize('0.01')")

def test_elements(self):
tax = lineartax('1.2345678', name='Silly Tax')
Expand Down

0 comments on commit 4df4bce

Please sign in to comment.