scripts: Fixed CsvInt(CsvFloat(mt.inf)) bypassing int/float cast

Turns out mt.isinf is happy to accept non-primitive floats (such as
CsvFloat) as long as __float__ is defined. But CsvInt expects a float
inf, not a CsvFloat, so things explode later.

Fixed by explicitly casting to float if mt.isinf, instead of passing
as-is.

Also tweaked CsvInt/CsvFloat constructors to not bother checking
isinstance, unconditional int/float casts are probably cheaper than the
condition in Python.
This commit is contained in:
Christopher Haster
2026-02-03 23:16:14 -06:00
parent f52ef58cf0
commit 8a4d114934
9 changed files with 10 additions and 30 deletions
+1 -3
View File
@@ -52,9 +52,7 @@ class CsvInt(co.namedtuple('CsvInt', 'a')):
a = -mt.inf
else:
raise
if not (isinstance(a, int) or mt.isinf(a)):
a = int(a)
return super().__new__(cls, a)
return super().__new__(cls, float(a) if mt.isinf(a) else int(a))
def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.a)