Adapt to Decimal repr change in Python 2.6
|Reported by:||Owned by:||Karen Tracey|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
In Python 2.6 (as of beta2) the repr for Decimal changed from using double to single quotes. Thus all of our tests that rely on Decimal repr fail like so:
Failed example: f.to_python(3) Expected: Decimal("3") Got: Decimal('3')
I asked about this over on the Python lists and feedback is the change is here to stay. Two suggestions for adapting the tests to be immune to the differences in repr across Python levels were:
1 - monkey-patch the Decimal module:
>>> import decimal >>> decimal.Decimal.__repr__ = lambda s: 'Decimal("%s")' % str(s)
2 - adapt the tests to use a style like this:
>>> f.to_python(3) == Decimal('3') True
instead of the style we have now. The first is easier but strikes me a bit hackish, the second is more work but might be a good style to move to generally if changing repr's are not seen as backwards-incompatible changes in Python.
Opinions on how we should adapt?