Skip to content

Add PyRange wrapper #5117

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

Merged
merged 3 commits into from
May 9, 2025
Merged

Add PyRange wrapper #5117

merged 3 commits into from
May 9, 2025

Conversation

bschoenmaeckers
Copy link
Member

No description provided.

@bschoenmaeckers bschoenmaeckers force-pushed the pyrange branch 4 times, most recently from 16fc2e4 to 3545ea6 Compare May 6, 2025 12:36
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.

Hmm, I'm not super sure how I feel about these. There is a similarity to both range and slice here, but having conversions mixed like this and turning some into range and others into slice feels like a footgun to me. And from the Rust side I find Range usually quite awkward to work with due to the limits their Iterator implementation imposes. So I'm also not sure if there is great value in us providing these. (maybe new_range_api could make a better interface in the future?)

Personally I think I'm leaning towards not having this (or dropping the conversions, I'd be fine with adding the type itself), but I'm keen to hear what others think about this.

@bschoenmaeckers
Copy link
Member Author

Yes, The similar but so different range and slice felt awkward when implementing IntoPyObject . I'm fine by leaving them out because I only needed PyRange type and included the conversions just for completeness . Will remove them for now.

@bschoenmaeckers bschoenmaeckers changed the title Add PyRange wrapper with conversions to/from std::ops::Range Add PyRange wrapper May 7, 2025
impl<'py> TryFrom<Bound<'py, PyRange>> for Bound<'py, PySlice> {
type Error = PyErr;

fn try_from(range: Bound<'py, PyRange>) -> Result<Self, Self::Error> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we should add a test for this conversion

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry I missed this, will add it in a followup PR.

@bschoenmaeckers bschoenmaeckers added this pull request to the merge queue May 9, 2025
Merged via the queue into PyO3:main with commit 3a39844 May 9, 2025
42 of 44 checks passed
@bschoenmaeckers bschoenmaeckers deleted the pyrange branch May 9, 2025 20:24
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.

2 participants