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

trim leading zeros before parsing str -> int #1266

Merged
merged 1 commit into from Apr 6, 2024
Merged

Conversation

samuelcolvin
Copy link
Member

@samuelcolvin samuelcolvin commented Apr 6, 2024

Change Summary

Trim leading zeros as well as other cleaning while coercing strings to ints.

Prior to #1250 we used str.parse::<i64>() and str.parse::<BigInt>() to coerce strings to integers, in #1250 we adopting the integer parsing logic from jiter (e.g. the logic we use to build integers from JSON strings), in JSON 0001 isn't a valid number, but I was unaware that str.parse::<i64>() did allow it, hence the break.

With this change we stripe leading zeros as part of other cleaning like striping whitespace, stripping .0+, and removing single underscores within the string.

Related issue number

Fix pydantic/pydantic#9165

Checklist

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with this pydantic-core (except for expected changes)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@samuelcolvin samuelcolvin changed the title trim leading zeros before parsing str->int trim leading zeros before parsing str -> int Apr 6, 2024
Copy link

codspeed-hq bot commented Apr 6, 2024

CodSpeed Performance Report

Merging #1266 will not alter performance

Comparing trim-zeros (52c7a2f) with main (e23d7eb)

Summary

✅ 155 untouched benchmarks

@samuelcolvin samuelcolvin enabled auto-merge (squash) April 6, 2024 12:28
@samuelcolvin samuelcolvin merged commit f636403 into main Apr 6, 2024
28 checks passed
@samuelcolvin samuelcolvin deleted the trim-zeros branch April 6, 2024 12:28
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.

Error when parsing a string as an integer
1 participant