Skip to content

Add PyRange wrapper#5117

Merged
bschoenmaeckers merged 3 commits intoPyO3:mainfrom
bschoenmaeckers:pyrange
May 9, 2025
Merged

Add PyRange wrapper#5117
bschoenmaeckers merged 3 commits intoPyO3:mainfrom
bschoenmaeckers:pyrange

Conversation

@bschoenmaeckers
Copy link
Copy Markdown
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
Copy Markdown
Member

@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.

Comment thread src/types/range.rs Outdated
Comment thread src/types/range.rs Outdated
@bschoenmaeckers
Copy link
Copy Markdown
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
Comment thread src/types/slice.rs
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
Copy Markdown
Member

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
Copy Markdown
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