Opened 11 years ago

Closed 10 years ago

Last modified 7 years ago

#7920 closed (fixed)

Adapt to Decimal repr change in Python 2.6

Reported by: Karen Tracey <kmtracey@…> Owned by: Karen Tracey
Component: Uncategorized Version: master
Severity: Keywords: python26
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: 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:

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')

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?

Attachments (2)

decimal.diff (3.4 KB) - added by Karen Tracey <kmtracey@…> 10 years ago.
decimal2.diff (3.5 KB) - added by Karen Tracey 10 years ago.
Forgot about Python 2.3 compatibility

Download all attachments as: .zip

Change History (8)

comment:1 Changed 11 years ago by Malcolm Tredinnick

Triage Stage: UnreviewedAccepted

I prefer the second one. The first looks a bit wrong to me, but it wouldn't be the end of the world if we went that way, either.

<editorial>Our tests are generally susceptible to subtle changes in output format like this. For example, if one of the VM-based pythons ever decided to use double-quotes instead of single quotes for default string printing, it'll be a real bunch of laughs. So it's not too surprising we have to change something like this now and again (although the Python guys could probably have managed to struggle on without making the change in the first place; it's hardly a requirement for functionality purposes. Still, it would be a Python release without some relatively pointless porting pain of this nature. :-( ).</editorial>

(Man, I wish people wouldn't put asides into comments like this. But I feel much better now that I've gotten that off my chest.)

comment:2 Changed 11 years ago by Karen Tracey

Owner: changed from nobody to Karen Tracey
Status: newassigned

Yeah, that's the feedback I got from the Python side. The tests as currently written are too dependent on output format, and the 2nd approach would be more future-proof if it were adopted in general throughout the tests. Not that I plan to do that, but just modifying the Decimal-dependent tests may result in people noticing/adopting a new idiom. (Or not, but one could hope.) I'll plan on taking the 2nd approach, then, unless I hear screams of protest from someone else.

Changed 10 years ago by Karen Tracey <kmtracey@…>

Attachment: decimal.diff added

comment:3 Changed 10 years ago by Karen Tracey <kmtracey@…>

Has patch: set

Added patch for changed in Decimal repr in Python 2.6. Tested against Python 2.6b2 and Python 2.5.1.

Changed 10 years ago by Karen Tracey

Attachment: decimal2.diff added

Forgot about Python 2.3 compatibility

comment:4 Changed 10 years ago by Karen Tracey

Updated patch for Python 2.3 compatibility, and tested with Python 2.3.5.

comment:5 Changed 10 years ago by Gary Wilson

Resolution: fixed
Status: assignedclosed

fixed in [8190].

comment:6 Changed 7 years ago by Jacob

milestone: 1.0 beta

Milestone 1.0 beta deleted

Note: See TracTickets for help on using tickets.
Back to Top