Issue1670

classification
Title: Implicit Decimal conversion to float fails
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
process
Status: open Resolution: remind
Dependencies: Superseder:
Assigned To: Nosy List: fwierzbicki, leosoto, mulleteer, pjenvey, zyasoft
Priority: Keywords:

Created on 2010-10-26.14:47:16 by mulleteer, last changed 2014-06-19.00:38:27 by zyasoft.

Messages
msg6210 (view) Author: Teemu (mulleteer) Date: 2010-10-26.14:47:15
Implicit Decimal conversion fails 

Jython 2.5.2rc2 (Release_2_5_2rc2:7167, Oct 24 2010, 22:48:30) 
[Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_21
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> from decimal import Decimal as D
>>> math.fabs(D('23.23'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: fabs(): 1st arg can't be coerced to double

But this works.

>>> math.fabs(float(D('23.23')))
23.23
msg6300 (view) Author: Philip Jenvey (pjenvey) Date: 2010-12-24.01:07:47
The problem here is Decimal's __tojava__ method does not handle the case of __tojava__(Double.class). We could fix that in Decimal but what would be better (in this respect) is having Decimal.__tojava__ fallback to super.__tojava__ when it doesn't know how to handle the conversion.

This would fix the problem because PyObject.__tojava__ will try conversion to Double.class via __float__.

We would have to expose __tojava__ on the object class for that fix though (it currently is not exposed to Python code). I'm not sure that's so good either
msg8689 (view) Author: Jim Baker (zyasoft) Date: 2014-06-19.00:38:15
Philip, I think it would be better if Decimal handles this explicitly rather than expose __tojava__, which seems likely to introduce other issues.
msg8690 (view) Author: Jim Baker (zyasoft) Date: 2014-06-19.00:38:27
Target beta 4
History
Date User Action Args
2014-06-19 00:38:27zyasoftsetmessages: + msg8690
versions: + Jython 2.7, - Jython 2.5
2014-06-19 00:38:15zyasoftsetnosy: + zyasoft
messages: + msg8689
2014-05-22 00:27:38zyasoftsetresolution: remind
2013-02-19 18:03:06fwierzbickisetnosy: + fwierzbicki
versions: + Jython 2.5, - 2.5.2b1
2010-12-24 01:07:48pjenveysetnosy: + pjenvey, leosoto
messages: + msg6300
2010-10-26 14:47:16mulleteercreate