From c314e245426315e4f3f5e04aa56d313380913828 Mon Sep 17 00:00:00 2001 From: Jacqueline Garrahan Date: Tue, 14 Jul 2026 14:52:47 -0700 Subject: [PATCH] Fix crash parsing non-finite numbers in namelists try_int() called int(x) unconditionally, which raises OverflowError on infinities and ValueError on NaN. number('inf'), number('nan'), and overflowing exponents like '1e400' therefore crashed the namelist parser on valid Fortran/Astra/Impact numeric output. Guard the int() conversion and return the float unchanged when it is not integral. Co-Authored-By: Claude Opus 4.8 (1M context) --- lume/parsers/numbers.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lume/parsers/numbers.py b/lume/parsers/numbers.py index b6361d2..2d7c994 100644 --- a/lume/parsers/numbers.py +++ b/lume/parsers/numbers.py @@ -16,10 +16,14 @@ def isbool(x): def try_int(x): - if x == int(x): - return int(x) - else: - return x + # int() raises on non-finite floats (inf/nan) and can overflow; such values + # (which appear in real Fortran/Astra/Impact numeric output) are left as-is. + try: + if x == int(x): + return int(x) + except (ValueError, OverflowError): + pass + return x def try_bool(x):