Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative integers with leading zeros raise ValueError #1436

Merged
merged 4 commits into from
Sep 5, 2024

Conversation

JBLDKY
Copy link
Contributor

@JBLDKY JBLDKY commented Sep 2, 2024

Change Summary

This PR addresses the inconsistency in handling negative integers with leading zeros in pydantic-core. It modifies the clean_int_str function to handle negative numbers with leading zeros consistently with positive numbers, allowing inputs like "-00042" to be correctly parsed as -42.

Related issue number

fix #1435

Checklist

  • Unit tests for the changes exist
  • [] Documentation reflects the changes where applicable (awaiting reply on the related issue)
  • [] Pydantic tests pass with this pydantic-core (except for expected changes) (awaiting reply on the related issue)
  • [] My PR is ready to review (awaiting reply on the related issue)

Implementation Details

The clean_int_str function in pydantic-core has been modified to:

  • Detect if the number is negative at the start of the function.
  • Remove the negative sign temporarily.
  • Apply the existing logic for removing leading zeros and underscores.
  • If the number was originally negative, reapply the negative sign.

This ensures consistent behavior for both positive and negative numbers with leading zeros.

Copy link

codecov bot commented Sep 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.29%. Comparing base (ab503cb) to head (ff5f5d1).
Report is 169 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1436      +/-   ##
==========================================
- Coverage   90.21%   89.29%   -0.92%     
==========================================
  Files         106      112       +6     
  Lines       16339    17724    +1385     
  Branches       36       41       +5     
==========================================
+ Hits        14740    15827    +1087     
- Misses       1592     1877     +285     
- Partials        7       20      +13     
Files with missing lines Coverage Δ
src/input/shared.rs 97.95% <100.00%> (+0.78%) ⬆️

... and 47 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d93e6b1...ff5f5d1. Read the comment docs.

Copy link

codspeed-hq bot commented Sep 2, 2024

CodSpeed Performance Report

Merging #1436 will not alter performance

Comparing JBLDKY:leading-zeros-after-unary-minus (ff5f5d1) with main (d93e6b1)

Summary

✅ 155 untouched benchmarks

Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@davidhewitt davidhewitt merged commit dec5faa into pydantic:main Sep 5, 2024
29 checks passed
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.

Inconsistent handling of negative integers with leading zeros
2 participants