From 8a4d1149340c930077511c7730564ab2342de448 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 3 Feb 2026 23:16:14 -0600 Subject: [PATCH] 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. --- scripts/code.py | 4 +--- scripts/cov.py | 4 +--- scripts/csv.py | 8 ++------ scripts/ctx.py | 4 +--- scripts/data.py | 4 +--- scripts/perf.py | 4 +--- scripts/perfbd.py | 4 +--- scripts/stack.py | 4 +--- scripts/structs.py | 4 +--- 9 files changed, 10 insertions(+), 30 deletions(-) diff --git a/scripts/code.py b/scripts/code.py index 58dcf5b8..f3419a72 100755 --- a/scripts/code.py +++ b/scripts/code.py @@ -51,9 +51,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) diff --git a/scripts/cov.py b/scripts/cov.py index beff654e..71626df2 100755 --- a/scripts/cov.py +++ b/scripts/cov.py @@ -53,9 +53,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) diff --git a/scripts/csv.py b/scripts/csv.py index 58e32b8f..1044df97 100755 --- a/scripts/csv.py +++ b/scripts/csv.py @@ -76,9 +76,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) @@ -186,9 +184,7 @@ class CsvFloat(co.namedtuple('CsvFloat', 'a')): a = -mt.inf else: raise - if not isinstance(a, float): - a = float(a) - return super().__new__(cls, a) + return super().__new__(cls, float(a)) def __repr__(self): return '%s(%r)' % (self.__class__.__name__, self.a) diff --git a/scripts/ctx.py b/scripts/ctx.py index 81ebc0ab..388ae8a9 100755 --- a/scripts/ctx.py +++ b/scripts/ctx.py @@ -47,9 +47,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) diff --git a/scripts/data.py b/scripts/data.py index ff3d395f..4c8a8558 100755 --- a/scripts/data.py +++ b/scripts/data.py @@ -51,9 +51,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) diff --git a/scripts/perf.py b/scripts/perf.py index 8c1a8d7c..9a2397b0 100755 --- a/scripts/perf.py +++ b/scripts/perf.py @@ -61,9 +61,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) diff --git a/scripts/perfbd.py b/scripts/perfbd.py index 70a1fb57..b751881a 100755 --- a/scripts/perfbd.py +++ b/scripts/perfbd.py @@ -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) diff --git a/scripts/stack.py b/scripts/stack.py index 42d4c49d..b5a44415 100755 --- a/scripts/stack.py +++ b/scripts/stack.py @@ -47,9 +47,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) diff --git a/scripts/structs.py b/scripts/structs.py index e2a5bc01..8d2cac5d 100755 --- a/scripts/structs.py +++ b/scripts/structs.py @@ -47,9 +47,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)