Skip to content

reject overlong decimal integer instead of coercing to inf#538

Open
netliomax25-code wants to merge 1 commit into
python-poetry:masterfrom
netliomax25-code:reject-overlong-integer
Open

reject overlong decimal integer instead of coercing to inf#538
netliomax25-code wants to merge 1 commit into
python-poetry:masterfrom
netliomax25-code:reject-overlong-integer

Conversation

@netliomax25-code

Copy link
Copy Markdown
Contributor

Summary

  1. _parse_number runs int(sign + clean, base) inside a try/except ValueError that, on failure, falls back to float(sign + clean).
  2. A decimal integer literal with more digits than Python's int-from-string limit (4300 by default) makes int() raise ValueError, so the literal is parsed as a float instead. A long run of digits ends up as inf, so a = 9999... (4301+ digits) silently returns a float inf rather than being rejected as an out-of-range integer.
  3. Restrict the float fallback to literals that are actually float-shaped (a fractional dot, a base-10 exponent, or inf/nan). An integer that int() cannot parse now returns None, so the parser raises InvalidNumberError. Hex/oct/bin literals (no digit limit) and all valid float literals are unaffected.

Repro: tomlkit.parse("a = " + "9" * 4301)["a"] returns float inf before the change; it raises InvalidNumberError after. The 4300-digit value still parses as an Integer.

Agent Drafting Metadata

  • Agent:
  • Model:
  • Notes:

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.

1 participant