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

add _bound constructors for datetime types #3778

Merged
merged 4 commits into from
Feb 12, 2024

Conversation

davidhewitt
Copy link
Member

@davidhewitt davidhewitt commented Jan 29, 2024

For #3684

This PR adds new_bound and variants for the PyDate, PyDateTime, PyTime and PyDelta types.

Also adds timezone_utc_bound.

Updates internal code to use these (basically the chrono conversions).

WIP - the pytests changes as written don't compile until #3776 allows &Bound<T> as a function argument.

@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Jan 29, 2024
@davidhewitt davidhewitt force-pushed the datetime-bound-constructors branch from 0ae7da3 to ad80c94 Compare February 5, 2024 09:35
@davidhewitt davidhewitt marked this pull request as ready for review February 5, 2024 09:35
@davidhewitt
Copy link
Member Author

Ok, I think this one should now be good to review! 🎉

Copy link

codspeed-hq bot commented Feb 5, 2024

CodSpeed Performance Report

Merging #3778 will not alter performance

Comparing davidhewitt:datetime-bound-constructors (43217dd) with main (1279467)

Summary

✅ 79 untouched benchmarks

tzinfo: Option<&PyTzInfo>,
) -> PyResult<&'p PyTime> {
PyTime::new(py, hour, minute, second, microsecond, tzinfo)
tzinfo: Option<&Bound<'_, PyTzInfo>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume the compiler is smart enough to figure out that the inner lifetime here has to be 'py, but maybe its nicer for consistency to explicitly name it if we have it named anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, I had been tempted to leave these out as it didn't feel strictly necessary. On refection just having 'py consistently added to all Bound (if the lifetime is named) is a simple rule which makes readable code 👍

I'll update the whole file.

src/ffi/tests.rs Outdated
@@ -79,7 +79,7 @@ fn test_timezone_from_offset() {
use crate::types::PyDelta;

Python::with_gil(|py| {
let delta = PyDelta::new(py, 0, 100, 0, false).unwrap();
let delta = PyDelta::new_bound(py, 0, 100, 0, false).unwrap();
let tz: &PyAny = unsafe { py.from_borrowed_ptr(PyTimeZone_FromOffset(delta.as_ptr())) };
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can remove this gil-ref (and the one below) as well, while we're here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. Reading this code I see they're also bugged. PyTimeZone_FromOffset is documented to return a new reference, so I'll change this to .assume_owned(py).

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfekt 👍

@davidhewitt davidhewitt force-pushed the datetime-bound-constructors branch from a45857c to 10cb090 Compare February 11, 2024 22:33
@davidhewitt
Copy link
Member Author

Thanks for the thorough review! In the spirit of #3811 I've chosen to push the review feedback as new commits to make it easier to see what I've updated.

Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

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

LGTM

@davidhewitt davidhewitt force-pushed the datetime-bound-constructors branch from 1ce1393 to 43217dd Compare February 12, 2024 20:33
@davidhewitt davidhewitt added this pull request to the merge queue Feb 12, 2024
Merged via the queue into PyO3:main with commit 5b9b76f Feb 12, 2024
33 of 38 checks passed
@davidhewitt davidhewitt deleted the datetime-bound-constructors branch February 12, 2024 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI-skip-changelog Skip checking changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants