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:
+1
-3
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user