diff --git a/json-test/json2.py b/json-test/json2.py index 7d53e4d407f5886dd71b20479aaf0bc3d527db80..9a426b3a3ffb4f2572c79fefd2e322e84ce7f6f6 100644 --- a/json-test/json2.py +++ b/json-test/json2.py @@ -58,13 +58,17 @@ def handle_int(xs: list[MatchObject]) -> list[int]: Note that this only works if adjacant joining is working. """ + assert type(xs[0]) is str return [int(xs[0])] def _handle_exp(parts: list[MatchObject]) -> list[int]: """Convert the exponential part of a float to its integer value.""" - total = force(__find('dig', parts)).matched[0] + dig = __find('dig', parts) + assert isinstance(dig, MatchCompound) + total = dig.matched[0] if sign := __find('sign', parts): + assert isinstance(sign, MatchCompound) if sign.matched[0][0] == '-': total *= -1 return [total] @@ -91,13 +95,16 @@ def _handle_number(parts: list[MatchObject]) -> list[float]: print(parts) # string: str = '' if base := __find('base', parts): + assert isinstance(base, MatchCompound) total += base.matched[0] if frac := __find('fractional', parts): + assert isinstance(frac, MatchCompound) d = frac.matched[0] total += d / 10**(math.floor(math.log10(d)) + 1) if exp := __find('exp', parts): + assert isinstance(exp, MatchCompound) total *= 10**exp.matched[0] if __find('minus', parts):