Conversation
- Add fallback to `float(v)` in `parse_bool` to correctly handle strings like "1.0", "inf", and "nan".
- Add optimized check to avoid performance penalty for common non-numeric strings.
- Add regression test `tests/unit/test_parse_bool_float_str.py`.
Impact: Fixes inconsistency where `parse_bool("1.0")` returned `False` while `parse_bool(1.0)` returned `True`.
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
π Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a π emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
- Add fallback to `float(v)` in `parse_bool` to correctly handle strings like "1.0", "inf", and "nan".
- Add optimized check to avoid performance penalty for common non-numeric strings.
- Add regression test `tests/unit/test_parse_bool_float_str.py`.
- Apply code formatting (black/isort) to test file.
Impact: Fixes inconsistency where `parse_bool("1.0")` returned `False` while `parse_bool(1.0)` returned `True`.
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
π Vulnerability:
parse_boolwas inconsistent when handling string representations of floating-point numbers.parse_bool("1.0")returnedFalsebecause it wasn't in the optimized boolean set, whereasparse_bool(1.0)returnedTrue. This could lead to data corruption when parsing numeric booleans from JSON APIs.π‘οΈ Defense: Updated
imednet/utils/validators.pyto attemptfloatconversion for strings that look numeric (start with digit, sign, '.', 'n', or 'i'). This ensures that "1.0", "inf", "nan", etc. are parsed consistently with Python'sfloatbehavior.π¬ Verification: Created
tests/unit/test_parse_bool_float_str.pywhich verifies that:True.False.Ran full test suite to ensure no regressions.
π Impact: Increases confidence in data parsing logic and prevents potential bugs in models that use
parse_bool(e.g.,JsonModel).PR created automatically by Jules for task 142145209111035684 started by @fderuiter