[IronPython] Unum problem

Sanghyeon Seo sanxiyn at gmail.com
Fri Oct 13 19:56:36 CEST 2006


I had a look at Unum problem. Still not figured it out. It's ugly.

Unum 4.0 source:
http://heanet.dl.sourceforge.net/sourceforge/unum/Unum-4.0.tar.gz

unum/__init__.py line 174 has:
"if conv is 0"

This is bad and no-no. It is an undefined behaviour to compare numbers
by reference. Actually,

CPython:
>>> 0 is 0
True

IronPython:
>>> 0 is 0
False

Strange thing is that if I change the line to "if conv == 0",
*CPython* errs too.

Here's the codepath leading to ZeroDivisionError in case someone wants
to investigate more:

1. unum.units.si is imported, and unum/units/si/__init__.py is executed.
2. 1 imports derived.py.
3. 2 imports base.py.
4. 3 imports Unum class from unum/__init__.py.
5. Unum.unit, a static method to define new units, is called.
6. A dummy Unum object is constructed with specified unit.
7. As a side effect of 6, class variable Unum._unitTable is modified.
8. While doing 7, line 174 above is executed, which sets:
8-1. conv_unum (conversion Unum) to None on CPython.
8-2. conv_unum to a new Unum with value of 0 on IronPython.
9. Unums are constructed. (Under different _unitTable)
10. Calculation is done without any problem.
11. To print the result of the calculation, __repr__ is called.
12. 11 calls __str__.
13. 12 calls normalize.
14. 13 looks up _unitTable to find the "simplest" representation.
15. 14 ignores _unitTable with conv_unum set to None, because they are
assumed to be "base unit".
16. Only IronPython executes the branch "if conv_unum is not None".
17. The branch in 16 calls replaced.
18. To replace units, replaced raises the value of conv_unum (which is
0) to the units to be converted to.

-- 
Seo Sanghyeon



More information about the Ironpython-users mailing list