Address review comments on PR #578: catch OverflowError in _parse_int and fix parse_float annotation - #584
Merged
Conversation
…s to int
- `get_float(True)` wrongly returned `0.0` (the default) because `bool`
failed the `is_float` type-check, `str(True)` produced `"True"`, and
`float("True")` raised `ValueError`. Now `parse_float` short-circuits
on any `bool`/`int` value and returns `float(val)` directly, so
`get_float(True)` → `1.0` and `get_float(False)` → `0.0`.
- `get_int("3.5")` wrongly returned the caller-supplied default instead
of `3` because `int("3.5")` raises `ValueError`. `_parse_int` now
falls back to `int(float(val))` so numeric strings with a fractional
part are truncated correctly.
- `get_int(True)` returned `True` (a `bool`) rather than the `int` `1`
because `isinstance(True, int)` is `True` and `_parse_with` returned
the value unchanged. `parse_int` now explicitly casts `bool` inputs
with `int(val)` before any further processing.
…_float annotation
Copilot
AI
changed the title
[WIP] Fix code based on review comments
Address review comments on PR #578: catch OverflowError in _parse_int and fix parse_float annotation
Jul 7, 2026
fabiocaccamo
marked this pull request as ready for review
July 7, 2026 11:01
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #584 +/- ##
=======================================
Coverage 98.32% 98.33%
=======================================
Files 64 64
Lines 2392 2399 +7
=======================================
+ Hits 2352 2359 +7
Misses 40 40
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
Addresses both comments in the review thread on PR #578. Since #578 comes from a fork, its commit was cherry-picked onto this branch first, then the review fixes applied on top.
_parse_intoverflow safety — theint(float(val))fallback introduced in fix: parse_float(bool/int) and parse_int(float-string) return wrong results #578 could raiseOverflowErrorfor inputs like"inf"or"1e309"(wherefloat(...)yields infinity), breakingget_int(...)callers instead of falling back to the default. The fallback now catches(ValueError, OverflowError)and returnsNone.parse_floattype annotation — signature updated fromval: strtoval: bool | float | int | strto reflect the input types it actually accepts.Related issue
?
Checklist before requesting a review