Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#7920 closed (fixed)

Adapt to Decimal repr change in Python 2.6

Reported by: Karen Tracey <kmtracey@…> Owned by: kmtracey
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: UI/UX:

Description

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?

Attachments (2)

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

Download all attachments as: .zip

Change History (8)

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 6 years ago by kmtracey

  • Owner changed from nobody to kmtracey
  • Status changed from new to assigned

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 6 years ago by Karen Tracey <kmtracey@…>

comment:3 Changed 6 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 6 years ago by kmtracey

Forgot about Python 2.3 compatibility

comment:4 Changed 6 years ago by kmtracey

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

comment:5 Changed 6 years ago by gwilson

  • Resolution set to fixed
  • Status changed from assigned to closed

fixed in [8190].

comment:6 Changed 3 years ago by jacob

  • milestone 1.0 beta deleted

Milestone 1.0 beta deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.