Skip to content

The type of infinity

 1 min Spyne’s unbounded defaults used float infinity, which made Decimal validation depend on the Python version.
Published

Jul 12, 2012

An unbounded numeric field still needs a representation for its bound. Spyne used float('inf') in several places, including around Decimal values. The sentinel looked universal; its comparisons were not.

My report and patch included a version comparison: Decimal('123.456') < float('inf') returned false in the reported Python 2.6 session and true in Python 2.7. That difference was breaking soft validation. The report also showed differing infinity hashes in 2.6, which agreed in 2.7.

The fix kept Decimal bounds in the Decimal domain:

gt = decimal.Decimal('-inf')
ge = decimal.Decimal('-inf')
lt = decimal.Decimal('inf')
le = decimal.Decimal('inf')

Changing those four defaults alone would have left other parts of the library expecting the old sentinel. The patch also updated string-length bounds, array cardinality, schema emission, tests, and documentation. When emitting XML Schema, a Decimal infinity still became the schema’s unbounded value.

The representation had to stay coherent across input configuration, validation, and output. Otherwise a caller could use the documented sentinel and have one stage recognize it while another treated it differently.

The patch merged. A sentinel participates in the operations performed on the values it bounds. Its type is part of the contract, even when the intended meaning is simply “no limit.”