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

defer to PyO3 i64 extraction to avoid implicit integer casts #1288

Merged
merged 1 commit into from
May 16, 2024

Conversation

davidhewitt
Copy link
Contributor

Change Summary

As per PyO3/pyo3#3742, the PyO3 logic for i64 extraction has workarounds for older Python versions which allowed float -> int casts in some contexts.

Related issue number

Fixes pydantic/pydantic#9018

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

@davidhewitt davidhewitt changed the title test for <= 3.9 implicit int casts defer to PyO3 i64 extraction to avoid implicit integer casts May 14, 2024
Comment on lines +76 to +78
# Python 3.9 and below allowed truncation of float to integers in some
# cases, by not making this an error we can test for this behaviour
'ignore:(.+)Implicit conversion to integers using __int__ is deprecated',
Copy link
Contributor Author

@davidhewitt davidhewitt May 14, 2024

Choose a reason for hiding this comment

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

By adding this ignore it allows the deprecated behaviour on older versions, thus testing them. Without the Rust change in this PR I get test failures locally which are consistent with pydantic/pydantic#9018.

Copy link

codspeed-hq bot commented May 14, 2024

CodSpeed Performance Report

Merging #1288 will not alter performance

Comparing dh/implicit-int (59af7b6) with main (aed6844)

Summary

✅ 155 untouched benchmarks

@davidhewitt
Copy link
Contributor Author

... except it looks like PyO3 gets PyPy wrong, because PyPy didn't change on 3.10 - pypy/pypy#4949

Copy link
Member

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

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

Great, thanks!

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.

Parsing of float as datetime changes depending on the deprecation warnings handling setting
2 participants