Skip to content

fix: catch OverflowError in _parse_int float fallback#589

Closed
fabiocaccamo with Copilot wants to merge 1 commit into
mainfrom
copilot/fix-code-review-comment
Closed

fix: catch OverflowError in _parse_int float fallback#589
fabiocaccamo with Copilot wants to merge 1 commit into
mainfrom
copilot/fix-code-review-comment

Conversation

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

_parse_int falls back to int(float(val)) for float-string inputs, but only caught ValueError. Inputs like "inf" or "1e309" produce float("1e309") → inf, and int(inf) raises OverflowError, bubbling up to get_int() callers instead of returning the default.

Changes

  • benedict/dicts/parse/parse_util.py: extend inner except to (ValueError, OverflowError) so overflow inputs return None cleanly
def _parse_int(val: str) -> int | None:
    try:
        return int(val)
    except ValueError:
        try:
            return int(float(val))
        except (ValueError, OverflowError):  # was: except ValueError
            return None
  • tests/dicts/parse/test_parse_dict.py: add "inf" and "1e309" cases to test_get_int, asserting both return the caller-supplied default

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have added tests for the proposed changes.
  • I have run the tests and there are not errors.

Copilot AI changed the title [WIP] Fix code based on review comment fix: catch OverflowError in _parse_int float fallback Jul 7, 2026
Copilot AI requested a review from fabiocaccamo July 7, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants